Advertisement
Guest User

Untitled

a guest
Jun 28th, 2017
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.86 KB | None | 0 0
  1. from itertools import permutations
  2.  
  3. SIZE = 4
  4.  
  5. def enforceIndexes(cindex):
  6. # for example,
  7. # clue #1 enforces cells 1,5,9,13 (of index),
  8. # clue #6 enforces cells 11,10,9,8. (watch out for the sequence)
  9. if 0 <= cindex < SIZE: return [cindex + SIZE * x for x in range(SIZE)]
  10. if SIZE <= cindex < SIZE * 2: return [(cindex - 4) * SIZE + SIZE - 1 - x for x in range(SIZE)]
  11. if SIZE * 2 <= cindex < SIZE * 3: return [3 * SIZE - 1 - cindex + 4 * (SIZE - 1 - x) for x in range(SIZE)]
  12. if SIZE * 3 <= cindex < SIZE * 4: return [(4 * SIZE - 1 - cindex) * 4 + x for x in range(SIZE)]
  13. else: raise ValueError('Wrong cindex!')
  14.  
  15. def possibleCombs():
  16. cluePossibles = [[] for i in range(SIZE)]
  17. for i in permutations([x+1 for x in range(SIZE)]):
  18. clue = 0
  19. highest = 0
  20. for v in i:
  21. if v > highest:
  22. clue += 1
  23. highest = v
  24. cluePossibles[clue - 1].append(i)
  25. return cluePossibles
  26.  
  27. def buildbinary(clues):
  28. # binary map:
  29. # 01101 - possible for 1,2,4
  30. # 01000 - possible for 4
  31. # 11101 - fixed for 2
  32. binary = [2 ** SIZE - 1 for i in range(SIZE ** 2)]
  33. cluePossibles = possibleCombs()
  34. cluePossibleLens = list(map(len, cluePossibles))
  35. # fill row/columns with clues that restricts cells the most first (i.e. clue = 4)
  36. fillSequence = sorted([i for i in range(SIZE ** 2) if clues[i] > 0], key = lambda x: cluePossibleLens[clues[x] - 1])
  37. clueTrack, clueSearchIndex, layerIndex = [], [], 0
  38. for i in fillSequence:
  39. clueTrack.append((i, cluePossibles[clues[i] - 1]))
  40. clueSearchIndex.append(0)
  41. while clueSearchIndex[0] < len(clueTrack[0][1]):
  42. # so not all clues have been proved invalid
  43.  
  44. def binaryFillLine(binary, clueIndex, line)
  45.  
  46.  
  47.  
  48.  
  49.  
  50. def solve_puzzle(clues):
  51.  
  52. return
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement