Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from itertools import permutations
- SIZE = 4
- def enforceIndexes(cindex):
- # for example,
- # clue #1 enforces cells 1,5,9,13 (of index),
- # clue #6 enforces cells 11,10,9,8. (watch out for the sequence)
- if 0 <= cindex < SIZE: return [cindex + SIZE * x for x in range(SIZE)]
- if SIZE <= cindex < SIZE * 2: return [(cindex - 4) * SIZE + SIZE - 1 - x for x in range(SIZE)]
- if SIZE * 2 <= cindex < SIZE * 3: return [3 * SIZE - 1 - cindex + 4 * (SIZE - 1 - x) for x in range(SIZE)]
- if SIZE * 3 <= cindex < SIZE * 4: return [(4 * SIZE - 1 - cindex) * 4 + x for x in range(SIZE)]
- else: raise ValueError('Wrong cindex!')
- def possibleCombs():
- cluePossibles = [[] for i in range(SIZE)]
- for i in permutations([x+1 for x in range(SIZE)]):
- clue = 0
- highest = 0
- for v in i:
- if v > highest:
- clue += 1
- highest = v
- cluePossibles[clue - 1].append(i)
- return cluePossibles
- def buildbinary(clues):
- # binary map:
- # 01101 - possible for 1,2,4
- # 01000 - possible for 4
- # 11101 - fixed for 2
- binary = [2 ** SIZE - 1 for i in range(SIZE ** 2)]
- cluePossibles = possibleCombs()
- cluePossibleLens = list(map(len, cluePossibles))
- # fill row/columns with clues that restricts cells the most first (i.e. clue = 4)
- fillSequence = sorted([i for i in range(SIZE ** 2) if clues[i] > 0], key = lambda x: cluePossibleLens[clues[x] - 1])
- clueTrack, clueSearchIndex, layerIndex = [], [], 0
- for i in fillSequence:
- clueTrack.append((i, cluePossibles[clues[i] - 1]))
- clueSearchIndex.append(0)
- while clueSearchIndex[0] < len(clueTrack[0][1]):
- # so not all clues have been proved invalid
- def binaryFillLine(binary, clueIndex, line)
- def solve_puzzle(clues):
- return
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement