Skip to content

Instantly share code, notes, and snippets.

@theotherzach
Last active August 29, 2015 14:07
Show Gist options
  • Save theotherzach/73592ec291deaf0fead4 to your computer and use it in GitHub Desktop.
Save theotherzach/73592ec291deaf0fead4 to your computer and use it in GitHub Desktop.
(ns clj-bowling.core)
(defn last-frame? [rolls]
(<= (count rolls) 3))
(defn strike? [rolls]
(= 10 (first rolls)))
(defn spare? [rolls]
(= 10 (sum (take 2 rolls))))
(defn sum [col]
(reduce + col))
(defn score [rolls]
(cond
(last-frame? rolls) (sum rolls)
(strike? rolls) (+ (sum (take 3 rolls)) (recur (nthrest rolls 1)))
(spare? rolls) (+ (sum (take 3 rolls)) (recur (nthrest rolls 2)))
:else (+ (sum (take 2 rolls)) (recur (nthrest rolls 2)))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment