Skip to content

Instantly share code, notes, and snippets.

@dnene
Created January 10, 2011 06:38
Show Gist options
  • Save dnene/772470 to your computer and use it in GitHub Desktop.
Save dnene/772470 to your computer and use it in GitHub Desktop.
Greed scoring in python
# Rules : https://github.com/edgecase/ruby_koans/blob/master/koans/GREED_RULES.txt
r = ((100,1000), (0,200), (0,300), (0,400), (50,500), (0,600))
def times(dct,val) :
dct[val-1] = dct[val-1] + 1
return dct
def score(dice) :
dct = reduce(times,dice,dict((x,0) for x in range(6)))
return reduce(lambda s, (t,c) : r[t][0] * (c % 3) + r[t][1] * (c / 3) + s,
dct.items(),0)
if __name__ == "__main__" :
assert score((5,1,3,4,1)) == 250
assert score((1,1,1,3,1)) == 1100
assert score((2,4,4,5,4)) == 450
@jneira
Copy link

jneira commented Jan 10, 2011

jumm too much terse?? :-P

@dnene
Copy link
Author

dnene commented Jan 10, 2011

Ha ha, .. truth be told I wrote it a little verbose and then tersified it. Though I think this structure (if translated to clojure) might actually work out quite nicely. :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment