from graph import DirectedGraph, trie_to_dawg
from bananagram import Bananagrams
lexicon = open('data/sowpods.txt', 'r').read()
G = DirectedGraph()
G.parselex(lexicon) # build prefix trie
trie_to_dawg(G) # reduce graph by merging suffixes
B = Bananagrams(G)
# Available tiles
rack = [s for s in 'lbwnytkmexroatiliaape']
sol = B.solve(rack)
B.show(sol) # Print solution!
""" Outputs:
3210123
2 P
1 MIB
0TI AA
1 R LAWN
2 Y L
3 O
4 T
5 E
6 KEX
"""
Randomly collect N letter tiles Use all N letters to make a Scrabble-like grid of words. If no solution exists, grab more tiles
- As N increases, how does likelihood of solution change? Where does the change occur?
- How does the behavior depend on the distribution of letters grabbable?
- Thanks to Alex Alemi for suggesting directed acyclic words graphs (DAWG)
- Appel and Jacobsen (1986) "The World's Fastest Scrabble Program"
- http://stevehanov.ca/blog/index.php?id=115