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

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:
    1,321
    Chris Theis
    Nov 13, 2003
  2. Runic911

    Palindrome

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

    Re: Re: Palindrome

    Tim Churches, Nov 13, 2003, in forum: Python
    Replies:
    2
    Views:
    921
    yousafzai
    Jun 5, 2011
  4. Pierre Quentel

    Re: Palindrome

    Pierre Quentel, Nov 13, 2003, in forum: Python
    Replies:
    2
    Views:
    667
    Francis Avila
    Nov 13, 2003
  5. cat_dog_ass

    Palindrome using StringBuffer

    cat_dog_ass, Jan 23, 2007, in forum: Java
    Replies:
    4
    Views:
    3,838
    abhi2varma
    Jan 5, 2013
  6. Tung Chau
    Replies:
    1
    Views:
    578
    SM Ryan
    Aug 6, 2004
  7. Replies:
    1
    Views:
    774
    Howard Hinnant
    Mar 27, 2006
  8. Robbie Hatley
    Replies:
    1
    Views:
    357
    Howard
    Apr 16, 2007
Loading...