Last active
December 24, 2020 10:49
-
-
Save leetwinski/6b8b58ed818a43611ef5618b84cf57f7 to your computer and use it in GitHub Desktop.
advent of code 2020-15
This file contains hidden or 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-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