So, you want to split 3 blocks of size 4.3.3, with (1,2,3) in one block and (7,8) in one block.
This means that 1,2,3 and 7,8 cannot be in one block.
Let me first forget the keyboard and analyze the problem
IMHO, you have to separate 3 cases:
- 1,2,3 are in a block of size 4 (case 1)
- 7.8 are in a block of size 4 (case 2)
- neither 1,2,3, nor 7,8, nor in a block of size 4 (case 3)
Case 1
- one element of (0,4,5,6,9) goes into a block containing (1, 2, 3)
- one element of (0,4,5,6,9) goes to the block containing (7,8)
total: 5 * 4 = 20 different sections
Case 2
- two elements from (0,4,5,6,9) go to the block containing (7,8)
total: 5 * 4/2 = 10 different sections (/ 2, because you want combinations, not permutations)
Case 3
- one element from (0,4,5,6,9) goes to the block containing (7,8)
total: 5 different sections
So, you know that you should have 35 different sections
Python Code:
def gen(): B1 = [1,2,3] B2 = [7,8] C = [x for x in range(10) if x not in B1 + B2 ] def gen1(): for x in C: c = C[:] b1 = B1[:] b1.append(x) c.remove(x) for y in c: c1 = c[:] b2 = B2[:] b2.append(y) c1.remove(y) yield(b1, b2, c1) def gen2(): for i in range(len(C)-1): for j in range(i+1, len(C)): b2 = B2 + [C[i], C[j]] c = [C[k] for k in range(len(C)) if k not in (i,j)] yield (B1, b2, c) def gen3(): for x in C: b2 = B2[:] c = C[:] c.remove(x) b2.append(x) yield(B1, b2, c) for g in (gen1, gen2, gen3): for t in g(): yield t
And you get it right:
>>> list(gen()) [([1, 2, 3, 0], [7, 8, 4], [5, 6, 9]), ([1, 2, 3, 0], [7, 8, 5], [4, 6, 9]), ([1, 2, 3, 0], [7, 8, 6], [4, 5, 9]), ([1, 2, 3, 0], [7, 8, 9], [4, 5, 6]), ([1, 2, 3, 4], [7, 8, 0], [5, 6, 9]), ([1, 2, 3, 4], [7, 8, 5], [0, 6, 9]), ([1, 2, 3, 4], [7, 8, 6], [0, 5, 9]), ([1, 2, 3, 4], [7, 8, 9], [0, 5, 6]), ([1, 2, 3, 5], [7, 8, 0], [4, 6, 9]), ([1, 2, 3, 5], [7, 8, 4], [0, 6, 9]), ([1, 2, 3, 5], [7, 8, 6], [0, 4, 9]), ([1, 2, 3, 5], [7, 8, 9], [0, 4, 6]), ([1, 2, 3, 6], [7, 8, 0], [4, 5, 9]), ([1, 2, 3, 6], [7, 8, 4], [0, 5, 9]), ([1, 2, 3, 6], [7, 8, 5], [0, 4, 9]), ([1, 2, 3, 6], [7, 8, 9], [0, 4, 5]), ([1, 2, 3, 9], [7, 8, 0], [4, 5, 6]), ([1, 2, 3, 9], [7, 8, 4], [0, 5, 6]), ([1, 2, 3, 9], [7, 8, 5], [0, 4, 6]), ([1, 2, 3, 9], [7, 8, 6], [0, 4, 5]), ([1, 2, 3], [7, 8, 0, 4], [5, 6, 9]), ([1, 2, 3], [7, 8, 0, 5], [4, 6, 9]), ([1, 2, 3], [7, 8, 0, 6], [4, 5, 9]), ([1, 2, 3], [7, 8, 0, 9], [4, 5, 6]), ([1, 2, 3], [7, 8, 4, 5], [0, 6, 9]), ([1, 2, 3], [7, 8, 4, 6], [0, 5, 9]), ([1, 2, 3], [7, 8, 4, 9], [0, 5, 6]), ([1, 2, 3], [7, 8, 5, 6], [0, 4, 9]), ([1, 2, 3], [7, 8, 5, 9], [0, 4, 6]), ([1, 2, 3], [7, 8, 6, 9], [0, 4, 5]), ([1, 2, 3], [7, 8, 0], [4, 5, 6, 9]), ([1, 2, 3], [7, 8, 4], [0, 5, 6, 9]), ([1, 2, 3], [7, 8, 5], [0, 4, 6, 9]), ([1, 2, 3], [7, 8, 6], [0, 4, 5, 9]), ([1, 2, 3], [7, 8, 9], [0, 4, 5, 6])]
(manual formatting for easier reading ...)