?

Log in

No account? Create an account

Dafydd's Journal

History

16th May 2009

11:09am:

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.)

Powered by LiveJournal.com