diff options
Diffstat (limited to 'day15.clj')
-rw-r--r-- | day15.clj | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/day15.clj b/day15.clj new file mode 100644 index 0000000..569c5fb --- /dev/null +++ b/day15.clj @@ -0,0 +1,20 @@ +(def data [5 2 8 16 18 0 1]) + +(defn doit [n] + (letfn [(rec [lasta lastb last i] + (if (<= i n) + (let [new-last (if (and (lasta last) (lastb last)) + (- (lastb last) (lasta last)) + 0)] + (recur (assoc lasta new-last (lastb new-last)) + (assoc lastb new-last i) + new-last + (inc i))) + last))] + (rec {} + (into {} (map-indexed #(vector %2 %1) data)) + (last data) + (count data)))) + +(doit 2019) ; => 517 +(doit 30000000) ; => 3303657 slow |