Amusement - rotational palindrome generator

P

Paul McGuire

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,756
Messages
2,569,535
Members
45,008
Latest member
obedient dusk

Latest Threads

Top