Created
March 28, 2014 01:03
-
-
Save alexpw/9822819 to your computer and use it in GitHub Desktop.
This file contains 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
(defn partition-by-frame | |
[coll] | |
(lazy-seq | |
(when-let [s (seq coll)] | |
(let [[x y z :as xyz] (take 3 s)] | |
(if (= 10 x) | |
(cons xyz (partition-by-frame (next s))) | |
(if (= 10 (+ x (or y 0))) | |
(cons xyz (partition-by-frame (drop 2 s))) | |
(cons [x y] (partition-by-frame (drop 2 s))))))))) | |
(defn score | |
[rolls] | |
(->> rolls | |
partition-by-frame | |
(take 10) | |
(map #(remove nil? %)) | |
(reduce (partial apply +) 0))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment