Thursday, June 28, 2012

Guess my number the functional way

Guess my number on python the functional way:
import random
def getnum() : return int(raw_input("your guess? "))
def match(guess, secret) : 
    r =  ( guess < secret and 'too low') or ( guess > secret and 'too high') or (guess == secret and 'You win!!')
    print r
    print
    return r

def loop(x,z):
    print "try #",z,
    return ('You win!!' != match(getnum(),x) and loop(x,z+1) ) or (z)

def guessnumber():
    secret = random.choice(range(101))
    times = loop(secret,1)
    print "Total # of try's = ",times
    print (times < 3 and "no way!!") or (times < 4 and "very good") or (times < 6 and 'slo-po') or (times > 5 and 'looser!!')
    return

Wednesday, June 27, 2012

Calculating the scrabble value of a word

def scrabble_value(word):
if len(word)==1:
       return 0
       val=dict(a=1,b=3,c=3,d=2,e=1,f=4,g=2,h=4,i=1,j=8,k=5,l=1,m=3,n=1,o=1,p  =3,q=10,r=1,s=1,t=1,u=1,v=4,w=4,x=8,y=4,z=10) 
return reduce(lambda x,y:x+y,map(lambda x:val[x],word)) 

Skydivers over Google IO

Watching skydivers jumping over SF for google I/O

Cool!

Flying trucks over Texas..

While chatting with a client I happened to mention a tornado that sent trucks flying not to far from where I live.. I had the feeling that he thought I was exaggerating..


Nope, we don't exaggerate here in Texas.. ;)

I loved that plane...


Paragliding over miraflores


Summer Soaring over North Texas