Note that there are some explanatory texts on larger screens.

plurals
  1. POCombinatoric question
    text
    copied!<p>I've got what I think is a "enumerative combinatoric" question.</p> <p>I need to choose 7 elements out of 15 with repetition and I'd like to know if there's an easy way to store all combination in an array and directly find the element I'm interested in.</p> <p>Basically I'm building a big lookup table (containing a very expensive to compute value) and I'd like to know if I can access it using a simple formula (note that this is not homework, check my profile).</p> <p>The number of combinations with repetition for 7 out of 15 is 116 280 (I double checked that it is correct).</p> <p>Here's the code :</p> <pre><code>public static void main(String[] args) { final Random r = new Random( System.currentTimeMillis() ); final List&lt;String&gt; ls = new ArrayList&lt;String&gt;(); for (int i = 0; i &lt; 15; i++) { for (int j = i; j &lt; 15; j++) { for (int k = j; k &lt; 15; k++) { for (int l = k; l &lt; 15; l++) { for (int m = l; m &lt; 15; m++) { for (int n = m; n &lt; 15; n++) { for (int o = n; o &lt; 15; o++) { ls.add( i + " " + j + " " + k + " " + l + " " + m + " " + n + " " + o + ": " + r.nextLong() ); } } } } } } } System.out.println( "We have " + ls.size() + " entries" ); System.out.println( "Entry @ 5,7,2,10,11,8,3 is " + getEntryAt(5,7,2,10,11,8,3) ); } private static String getEntryAt( int i, int j, int k, int l, int m, int n, int o ) { return "FILL ME"; // What goes here ? } </code></pre> <p>In the above example I'm just putting a random value in the lookup array but this is basically it: I want to get, say, (5,7,2,10,11,8,3), can I "compute" easily it's location?</p> <p>Note that the way I'm storing elements in the array has no importance: I can store them in the way that makes for the fastest "formula", if any.</p> <p>If anyone knows what I'm talking about any help would be much welcome.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload