Last active
August 29, 2015 14:07
-
-
Save theotherzach/73592ec291deaf0fead4 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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