Created
December 17, 2015 17:32
-
-
Save sbenhaim/5725551f705b56712c61 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
(ns advent.a10) | |
(defn look-and-say [ls] | |
(flatten (for [l (partition-by identity ls)] | |
[(count l) (first l)]))) | |
(defn str->ints [s] | |
(map #(Integer/parseInt (str %)) s)) | |
(time | |
(let [n 50 | |
input "1321131112"] | |
(count | |
(reduce (fn [x _] (look-and-say x)) (str->ints input) (range n))))) | |
;; ~3 seconds for 40 | |
;; ~60 seconds for 50 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment