Skip to content

Instantly share code, notes, and snippets.

@sbenhaim
Created December 17, 2015 17:32
Show Gist options
  • Save sbenhaim/5725551f705b56712c61 to your computer and use it in GitHub Desktop.
Save sbenhaim/5725551f705b56712c61 to your computer and use it in GitHub Desktop.
(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