16 May 2009 dgh   » (Journeyer)

dgh @ 2009-05-16T11:09:00

Futility Closet, ever edifying, notes that the word “ravine” is reversed when rot13 is applied. Are there other words that have the same property? We can easily find out with a bit of code:

> import qualified Data.ByteString.Char8 as B
> 
> rot13 = B.map (toEnum . r . fromEnum)
>    where r c | (65 <= c) && (c <= 90)  = (c - 65 + 13) `mod` 26 + 65
>              | (97 <= c) && (c <= 122) = (c - 97 + 13) `mod` 26 + 97
>              | otherwise = c
> 
> main = B.interact (B.unlines . filter (\x -> rot13 x == B.reverse x) . B.lines)

The answer: not many. Running this on /usr/share/dict/words yields a paltry 12 words; all of which, “ravine” excepted, are four letters or less. We get slightly better results running it on the 390,583-word british-english-huge file from 12dicts (which I keep installed for exactly this sort of tomfoolery). On the other hand, some of the extra words are quite obscure. The full list:

an anan cherup fans fobs fs gant gnat grivet na nana ravine re rebore rive robe serf tang thug uh

(This post can be compiled by saving it as a .lhs file and running ghc --make on it.)

Syndicated 2009-05-16 08:35:52 from Dafydd

Latest blog entries     Older blog entries

New Advogato Features

New HTML Parser: The long-awaited libxml2 based HTML parser code is live. It needs further work but already handles most markup better than the original parser.

Keep up with the latest Advogato features by reading the Advogato status blog.

If you're a C programmer with some spare time, take a look at the mod_virgule project page and help us with one of the tasks on the ToDo list!