Example #1
0
    while stack:
        worda, wordb, search = stack.pop()
        patha = words.get_path(worda)
        pathb = words.get_path(wordb)
        if patha.has_a_word() and pathb.has_a_word():
            return (hidden, worda, wordb)
        else:
            for i in range(0, len(search)):
                if patha.has_path(search[i]):
                    stack.append((worda + search[i], wordb, search[i + 1:]))
                if pathb.has_path(search[i]):
                    stack.append((worda, wordb + search[i], search[i + 1:]))

# ------------------------------------------------------------
# constants
# ------------------------------------------------------------
HIDDEN = [
    'thiecbeigachgiell',
    'betfworilesigunshett',
    'tcrafafrisc',
    'tlawbyirsintther'
]
WORDS  = set(Words.get_word_list('movies'))

if __name__ == "__main__":
    words = Trie()
    words.add_words(WORDS)
    for hidden in HIDDEN:
        solution = find_solutions(words, hidden)
        print_solution(solution)
Example #2
0
    :param solutions: The final solutions for the problem
    '''
    for original, letter, solution in solution[0]:
        print "%s + %s → %s" % (original, letter, solutions)
    print '= %s' % solution[1]

# ------------------------------------------------------------
# constants
# ------------------------------------------------------------
WORDS    = set(Words.get_word_list())
M_LOOKUP = Words.generate_missing_lookup(WORDS)
W_LOOKUP = Words.generate_anagram_lookup(WORDS)
MISSING  = [
    'sarong',
    'gown',
    'shirt',
    'raincoat',
    'apron',
    'sweater',
    'cape'
]

if __name__ == "__main__":
    import pickle
    anagram_trie = Trie()
    anagram_trie.add_words(W_LOOKUP.keys())
    solutions = get_possible_solutions(M_LOOKUP, MISSING)
    #solutions = pickle.load(open('/tmp/solutions', 'rb'))
    for solution in find_final_solution(W_LOOKUP, anagram_trie, solutions):
        print_solution(solution)