Guest User

How many combinations (Math Stackexchange)

a guest
Dec 27th, 2018
139
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.78 KB | None | 0 0
  1. original = {1:[2,4,5,6,8],
  2.             2:[1,3,4,5,6,7,9],
  3.             3:[2,4,5,6,8],
  4.             4:[1,2,3,5,7,8,9],
  5.             5:[1,2,3,4,6,7,8,9],
  6.             6:[1,2,3,5,7,8,9],
  7.             7:[2,4,5,6,8],
  8.             8:[1,3,4,5,6,7,9],
  9.             9:[2,4,5,6,8]
  10.             }
  11.  
  12. def legals(current):
  13.     curr = current[-1]
  14.     if (not curr%2) and 5 in current:
  15.         extras = [10-curr]
  16.     else:
  17.         tocheck = [2*x-curr for x in [2,4,5,6,8] if x in current]
  18.         extras = [x for x in tocheck if x in range(1,10)]
  19.  
  20.     return list(set([x for x in (original[current[-1]]+extras) if x not in current]))
  21.  
  22. possibles = [[x] for x in range(1,10)]
  23. for j in range(3-1):
  24.     newposs = [i+[x] for i in possibles for x in legals(i)]
  25.     possibles = newposs
  26. for j in range(6):
  27.     newposs = [i+[x] for i in possibles for x in legals(i)]
  28.     possibles = newposs
  29.     print(len(possibles))
Add Comment
Please, Sign In to add comment