Circular Logic - "glow"

The NYTimes has a regular column on math puzzles. I don't usually look at them, but when I do I prefer Dos Equis... what? Oh yes, Numberplay. Most of the time I can't be bothered to figure out the answer, but one of the questions this week happens to be computationally easy. The question is:

Consider the word "glow." If you replace each letter with its counterpart in a mirror alphabet you will get the legitimate word "told." What other words exhibit this same property?

So I started wrote a little script in Python:

#!/usr/bin/env python3
import re
if __name__ == "__main__":
    src = open("/usr/share/dict/cracklib-small", "r")
    words = set()
    for word in src:
        word = word.strip()
        if len(word) == 1 or re.match('[^a-z]', word):
            continue
        words.add(word)
    src.close()
    for word in words:
        mirror = "".join(chr(219-ord(c)) for c in word)
        if mirror in words:
            print(word, mirror)

This script uses the computer's dictionary file (which I've used before), mutates the letters, then checks if the result is in the dictionary. The script outputs:

all   zoo
ark   zip
art   zig
blip  york
de    wv
dr    wi
drib  wiry
elm   von
era   viz
err   vii
fir   uri
fm    un
ge    tv
girl  trio
girt  trig
glib  tory
glow  told
gm    tn
gs    th
hob   sly
hold  slow
holt  slog
holy  slob
horn  slim
ir    ri
irk   rip
iv    re
ivy   reb
levi  over
low   old
lug   oft
md    nw
me    nv
mix   nrc
mn    nm
mrs   nih
ms    nh
nh    ms
nih   mrs
nm    mn
nrc   mix
nv    me
nw    md
oft   lug
old   low
over  levi
re    iv
reb   ivy
ri    ir
rip   irk
slim  horn
slob  holy
slog  holt
slow  hold
sly   hob
th    gs
tn    gm
told  glow
tory  glib
trig  girt
trio  girl
tv    ge
un    fm
uri   fir
vii   err
viz   era
von   elm
wi    dr
wiry  drib
wv    de
york  blip
zig   art
zip   ark
zoo   all

As a sanity check, notice that "glow" does indeed turn into "told" (and vice versa).

Problem solved in 10 minutes.

PS. I would have commented on the post, but I have no clue what my NYTimes password is.
No comments