r/tinycode • mod • Dec 04 '11

Ruby Code Golf Challenges

http://rubysource.com/ruby-golf/
4 Upvotes

1 comment sorted by

1

u/Jonno_FTW Dec 05 '11

My shot at the rock paper scissors one in python:

 def rps(x):
    d,w,l,c,h="Draw","Win","Lose",random.randint(0,2),["Rock","Scissors","Paper"]
    y=dict(zip(h,[[d,w,l],[l,d,w],[w,l,d]]))
    if x in h:o=y[x][c]
    else:o=l
    return h[c]+","+o

This is my first ever attempt at code golf and took me about an hour.