diff options
author | Leah Neukirchen <leah@vuxu.org> | 2021-12-07 18:32:49 +0100 |
---|---|---|
committer | Leah Neukirchen <leah@vuxu.org> | 2021-12-07 18:32:49 +0100 |
commit | fa4b58b6ce7e011ee2b88e86648678c6bcd06e66 (patch) | |
tree | 4028ef4a79d61b2ef97fad1542515f74e3a6fb49 /day06.clj | |
parent | be4d9f70ca06d1c1c21c7506d06d263a579d44a5 (diff) | |
download | adventofcode2021-fa4b58b6ce7e011ee2b88e86648678c6bcd06e66.tar.gz adventofcode2021-fa4b58b6ce7e011ee2b88e86648678c6bcd06e66.tar.xz adventofcode2021-fa4b58b6ce7e011ee2b88e86648678c6bcd06e66.zip |
day06
Diffstat (limited to 'day06.clj')
-rw-r--r-- | day06.clj | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/day06.clj b/day06.clj new file mode 100644 index 0000000..e674209 --- /dev/null +++ b/day06.clj @@ -0,0 +1,22 @@ +(ns org.vuxu.aoc2021.day06 + (:require [clojure.string :as str])) + +(def data + (let [values (->> (str/split (str/trim-newline (slurp "day06")) #",") + (mapv parse-long))] + (mapv #(count (filter #{%} values)) (range 0 9)))) + +(defn stepv [fishes] + (mapv (fn [i] + (cond (= i 8) (fishes 0) + (= i 6) (+ (fishes 0) (fishes (inc i))) + :else (fishes (inc i)))) + (range 0 9))) + +(def part1 + (apply + (nth (iterate stepv data) 80))) +;; => 373378 + +(def part2 + (apply + (nth (iterate stepv data) 256))) +;; => 1682576647495 |