Amusement - rotational palindrome generator

Paul McGuire ptmcg at austin.rr.com
Thu Dec 20 12:26:04 EST 2007


Here is some semi-obfuscated Python, to generate rotational
palindromes:

from random import choice

base = "sznuoxpqbdMWOINZXSH"
rot = dict(zip(base,"szunoxdbqpWMOINZXSH"))

for i in range(40):
    s1 = [choice(base) for j in range(choice((2,3,4)))]
    start = (1,2)[rot[s1[-1]]==s1[-1] and choice((True,False))]
    s2 = [rot[c] for c in s1[-start::-1]]
    print "".join(s1+s2)


Enjoy!

-- Paul



More information about the Python-list mailing list