diff options
author | Leah Neukirchen <leah@vuxu.org> | 2020-12-16 20:38:55 +0100 |
---|---|---|
committer | Leah Neukirchen <leah@vuxu.org> | 2020-12-16 20:38:55 +0100 |
commit | 580d09701f0377c4b80e6ea52cf8fa6b647778b1 (patch) | |
tree | 2e3ef57dfb00c94d6c9bfbb0b7a64bf73a9f419f /day15.clj | |
parent | 76933fddfe8deb9d18c40ea974bbe71bbc7dd319 (diff) | |
download | adventofcode2020-580d09701f0377c4b80e6ea52cf8fa6b647778b1.tar.gz adventofcode2020-580d09701f0377c4b80e6ea52cf8fa6b647778b1.tar.xz adventofcode2020-580d09701f0377c4b80e6ea52cf8fa6b647778b1.zip |
day15
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 |