Skip to content

Instantly share code, notes, and snippets.

@alexpw
Created March 28, 2014 01:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alexpw/9822819 to your computer and use it in GitHub Desktop.
Save alexpw/9822819 to your computer and use it in GitHub Desktop.
(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