Skip to content

Instantly share code, notes, and snippets.

@leetwinski
Last active December 24, 2020 10:49
Show Gist options
  • Save leetwinski/6b8b58ed818a43611ef5618b84cf57f7 to your computer and use it in GitHub Desktop.
Save leetwinski/6b8b58ed818a43611ef5618b84cf57f7 to your computer and use it in GitHub Desktop.
advent of code 2020-15
(ns advent-2020-15)
(def seed [1,2,16,19,18,0])
(defn next-num [[data [i n]]]
[(assoc data n i)
[(inc i)
(- i (data n i))]])
(defn nth-num [seed n]
(->> [(into {} (map vector (butlast seed) (range)))
[(dec (count seed)) (last seed)]]
(iterate next-num)
(map second)
(drop-while #(< (first %) (dec n)))
first))
;; part 1
(nth-num seed 2020)
;; part 2
(nth-num seed 30000000)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment