Skip to content

Instantly share code, notes, and snippets.

@jneira
Forked from xaviuzz/greed.rb
Created January 5, 2011 20:00
Show Gist options
  • Save jneira/766918 to your computer and use it in GitHub Desktop.
Save jneira/766918 to your computer and use it in GitHub Desktop.
;; Ultimo commit con propuestas brillantes de http://twitter.com/_ogf_
(defn score-single [ps]
(case ps 1 100 5 50 0))
(defn score-triple [ps]
(case ps 1 1000 (* ps 100)))
(defn scores-by-freq [[ps freq]]
[(* (quot freq 3)
(score-triple ps))
(* (mod freq 3)
(score-single ps))])
(defn score [dice-roll]
(->> (frequencies dice-roll)
(mapcat scores-by-freq)
( apply +)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment