about summary refs log tree commit diff
path: root/day06.clj
diff options
context:
space:
mode:
Diffstat (limited to 'day06.clj')
-rw-r--r--day06.clj22
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