#!/usr/bin/python3 # # Script to solve https://www.geocaching.com/geocache/GC7M808 # (that is a premium geocache; the link probably won't work) # # The sudoku puzzle has been broken into (9) 3x3 tiles. One # is pinned to the upper left. One to the lower right. The # other seven have unknown placement. # # THUS: find the right placement of the seven tiles, # AND solve the sudoku puzzle once properly placed # import itertools import sudoku2 # Specify each of the tiles T1 = ' 5 1 6 ' T2 = '5 4 6 ' T3 = '3 9 4 ' T4 = ' 8 1 ' T5 = ' 9358 ' T6 = '9 6 2 4 ' T7 = ' 7 3 2 ' T8 = ' 9 28 174' T9 = '7 ' PLACE = (T2, T3, T4, T5, T6, T7, T8) def main(): for idx, perm in enumerate(itertools.permutations(PLACE)): #if idx != 2874: continue # the solution # We already know there are no solutions. if idx <= 1237: pass#continue #print('PERM:', perm) puz = sudoku2.Puzzle() try: add_tile(puz, 0, T1) for t, info in enumerate(perm): add_tile(puz, t+1, info) add_tile(puz, 8, T9) except sudoku2.IllegalPuzzle: continue print(f'Found possible puzzle at #{idx}') #puz.printout() try: solved = puz.solve() except sudoku2.IllegalPuzzle: print(' >> no solution') continue except Exception as e: print('FAILED:', e) puz.printout() break if solved: print(f'Solved puzzle:') puz.printout() ### see if there are other solutions #break def add_tile(puz, t, info): tile = puz.tiles[t] for i, v in enumerate(info): if v == ' ': continue tile.cells[i].solve(int(v)-1) # input is 1-based if __name__ == '__main__': main()