Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>This was the general solution I found for all values of Set and Line Length. The first assumes you want no two solutions to share the same common element but you want each solution to have one element in common with every other solution. Given an infinite pool to pick form, the total number of solutions is limited by the length of each solution. </p> <pre><code>SET_LENGTH = 10 CHOICE_LENGTH = 300 data = set(range(CHOICE_LENGTH)) solutions =[] solution_sets = [] used = set() while True: new_solution = [] #Try to get unique values from each previous set try: for sol_set in solution_sets: while True: candidate = sol_set.pop() if not candidate in used: new_solution.append(candidate) used.update([candidate]) break except KeyError, e: print e break #Fill with new data until the line is long enough try: while len(new_solution) &lt; SET_LENGTH: new_solution.append(data.pop()) except KeyError, e: print e break solutions.append(new_solution) solution_sets.append(set(new_solution)) #Show the results for solution in solutions: print solution print "Orphans %s" % len(data) </code></pre> <p>For Example n = 300 x = 10 yields:</p> <pre><code>[0, 1, 2, 3, 4, 5, 6, 7, 8, 9] [0, 10, 11, 12, 13, 14, 15, 16, 17, 18] [1, 10, 19, 20, 21, 22, 23, 24, 25, 26] [2, 11, 19, 27, 28, 29, 30, 31, 32, 33] [3, 12, 20, 32, 34, 35, 36, 37, 38, 39] [4, 13, 21, 33, 34, 40, 41, 42, 43, 44] [5, 14, 22, 27, 36, 40, 45, 46, 47, 48] [6, 15, 23, 28, 37, 41, 45, 49, 50, 51] [7, 16, 24, 29, 38, 42, 47, 49, 52, 53] [8, 17, 25, 30, 39, 43, 48, 50, 52, 54] [9, 18, 26, 31, 35, 44, 46, 51, 53, 54] Orphans 245 </code></pre> <p>If you don't care how many solutions share the same common element then it's even easier:</p> <pre><code>SET_LENGTH = 2 CHOICE_LENGTH = 300 data = set(range(CHOICE_LENGTH)) solutions =[] alpha = data.pop() while True: new_solution = [alpha] try: [new_solution.append(data.pop()) for x in range(SET_LENGTH-1)] except KeyError, e: break solutions.append(new_solution) for solution in solutions: print solution print "Solutions: %s" % len(solutions) print "Orphans: %s" % len(data) </code></pre>
 

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