Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
UserDict solution in Clear category for Cipher Crossword by gyahun_dash
from collections import UserDict
from itertools import chain, permutations
class ConsistentDict(UserDict):
def __setitem__(self, key, item):
if not key in self.keys(): self.data[key] = item
elif self[key] != item: raise ValueError #prohibit updates
def enumerate_numbers_on(grid): #line: rows[0, 2, 4], columns[0, 2, 4]
for line in chain(grid[::2], list(zip(*grid))[::2]): yield from line
#arrange numbers in a line, and find consistent mapping(brute force)
def checkio(crossword, words):
line = list(enumerate_numbers_on(crossword))
for candidate_words in permutations(words):
try: cdict = ConsistentDict(zip(line, ''.join(candidate_words)))
except ValueError: continue
else: return [[cdict.get(n, ' ') for n in row] for row in crossword]
March 16, 2014
Comments: