Sunday, July 31, 2011

Universe.py - A Buddhist Poem In Python

import random

def samsara():
 
    enlightened = False
    lifetimes_of_ignorance = 0
    karma = 0
    buddha_karma = 42 ** 42

    while not enlightened:
        karma += random.randint(buddha_karma / -42, buddha_karma / 42)
     
        if karma < buddha_karma:
            lifetimes_of_ignorance += 1
        else:
            days_sitting = 0
            while days_sitting < 7:            
                days_sitting += 1
                if days_sitting == 7:
                    enlightened = True
                    print('You achieved enlightenment after %i lifetimes of ignorance. Enjoy!' % lifetimes_of_ignorance)

samsara()

#To try it:
#1.) go to http://codepad.org
#2.) select python as the language
#3.) paste in the whole poem
#4.) click submit

1 comment:

  1. This was a project for a class on experimental form at the Naropa Summer Writing Program in Boulder, CO about a year ago -- www.naropa.edu/swp/

    ReplyDelete