Thursday, July 17, 2008
Tropologs and Rotasmagrams
Some friends and I were discussing words today that look the same when rotated 180 degrees, which we've dubbed Rotasmagrams (or Tropologs, depending on whichever tickles your fancy more).
We successfully came up with "pod" and "suns". And then we wrote a script to generate the rest:
Reading in /usr/share/dict/words
Generating stems
Computing valid tropologs
unsun
un
suns
sooloos
pod
nu
dop
dollop
SIS
OHO
NOON
NON
MOW
IHI
I
Note that there is some controversy over the use of the lowercase letter 'l', which will tend to droop a bit when rotated. Also, it's clear that /usr/share/dict/words has some pretty unwordy words in it ("sooloos?").
#!/usr/bin/env python
DICT_FILE='/usr/share/dict/words'
TROPOLOGS = { 'b':'q', 'd':'p', 'n':'u', 'q':'b', 'p':'d', 'u':'n', 'o':'o', 's':'s', 'z':'z', 'l':'l',
'H':'H', 'I':'I', 'N':'N', 'O':'O', 'S':'S', 'X':'X', 'Z':'Z', 'M':'W' }
def potential_words(word):
words = [];
for i in TROPOLOGS.keys():
new_word = i + word + TROPOLOGS[i]
if new_word.lower() in VALID_STEMS:
words += [ new_word ] + potential_words(new_word)
return words
def mysort(l):
l.sort() # I hate that python's builtin sort doesn't return the list
l.reverse()
return l
print "Reading in " + DICT_FILE # dict file is mysteriously missing 'suns'
VALID_WORDS = [ word.lower() for word in open(DICT_FILE).read().splitlines() ] + ['suns']
print "Generating stems"
VALID_STEMS = {}
for word in VALID_WORDS:
for i in range(0, len(word)+1):
for j in range(i+1, len(word)+1):
VALID_STEMS[word[i:j]] = True
print "Computing valid tropologs"
potentials = ['I']
for word in [''] + [ x for x in TROPOLOGS.keys() if x==TROPOLOGS[x] ]:
potentials += potential_words(word)
# Strip out duplicates with different capitalization
tmp={}
for word in mysort([ word for word in potentials if word.lower() in VALID_WORDS and ( word == word.lower() or word == word.upper() ) ]):
if not word.lower() in tmp.keys(): print word
tmp[word.lower()] = word
Comments:
Post a Comment