Target cheat sheet
B | O | H |
C | N | K |
R | E | W |
I have a friend who sends me the Target puzzle from the Sydney Morning Herald every day. I’ve loved doing anagrams for as long as I can remember. I used to write many programs to process words for fun. At Waterloo I made lots of silly dictionaries with my friend Andrew Hensel. We used to make anagram dictionaries for fun reference and memorization.
Anyway, I decided to whip up an anagram dictionary maker in Python. Here’s the code:
import sys
from collections import defaultdict
words = defaultdict(list)
print '<html><head><title>Target cheat sheet.</title></head><body>'
for word in (line[:-1] for line in sys.stdin):
words[''.join(sorted(list(word.lower())))].append(word)
for letters in sorted(words.keys()):
print '<strong>%s</strong> = ' % letters
for word in sorted(words[letters], key=str.lower):
print word
print '</body></html>'
I built the dictionary with the shell command
awk 'length($0) == 9 {print}' /usr/share/dict/web2 | ./anagram-dict.py > target.html
and you can see the result here. To use it, you take your anagram, sort its letters, and look up the result in that web page. For example, today’s anagram is “bohcnkrew”. Sorting those 9 letters we get “bcehknorw”. Looking at the results page (use the Find function in your browser!) we see two answers: “benchwork” and “workbench”.
You can follow any responses to this entry through the RSS 2.0 feed. Both comments and pings are currently closed.