Amusement - rotational palindrome generator

Discussion in 'Python' started by Paul McGuire, Dec 20, 2007.

  1. Paul McGuire

    Paul McGuire Guest

    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
    Paul McGuire, Dec 20, 2007
    #1
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Lorin Leone

    Palindrome (HELP)

    Lorin Leone, Nov 12, 2003, in forum: C++
    Replies:
    4
    Views:
    995
    Chris Theis
    Nov 13, 2003
  2. Runic911

    Palindrome

    Runic911, Nov 13, 2003, in forum: Python
    Replies:
    24
    Views:
    1,566
    Andrew Dalke
    Nov 15, 2003
  3. Tim Churches

    Re: Re: Palindrome

    Tim Churches, Nov 13, 2003, in forum: Python
    Replies:
    2
    Views:
    723
    yousafzai
    Jun 5, 2011
  4. Replies:
    1
    Views:
    474
    Howard Hinnant
    Mar 27, 2006
  5. Robbie Hatley
    Replies:
    1
    Views:
    283
    Howard
    Apr 16, 2007
Loading...

Share This Page