about summary refs log tree commit diff
diff options
context:
space:
mode:
authorLeah Neukirchen <leah@vuxu.org>2021-12-07 18:32:49 +0100
committerLeah Neukirchen <leah@vuxu.org>2021-12-07 18:32:49 +0100
commitfa4b58b6ce7e011ee2b88e86648678c6bcd06e66 (patch)
tree4028ef4a79d61b2ef97fad1542515f74e3a6fb49
parentbe4d9f70ca06d1c1c21c7506d06d263a579d44a5 (diff)
downloadadventofcode2021-fa4b58b6ce7e011ee2b88e86648678c6bcd06e66.tar.gz
adventofcode2021-fa4b58b6ce7e011ee2b88e86648678c6bcd06e66.tar.xz
adventofcode2021-fa4b58b6ce7e011ee2b88e86648678c6bcd06e66.zip
day06
-rw-r--r--day061
-rw-r--r--day06.bqn5
-rw-r--r--day06.clj22
3 files changed, 28 insertions, 0 deletions
diff --git a/day06 b/day06
new file mode 100644
index 0000000..445de95
--- /dev/null
+++ b/day06
@@ -0,0 +1 @@
+1,1,3,1,3,2,1,3,1,1,3,1,1,2,1,3,1,1,3,5,1,1,1,3,1,2,1,1,1,1,4,4,1,2,1,2,1,1,1,5,3,2,1,5,2,5,3,3,2,2,5,4,1,1,4,4,1,1,1,1,1,1,5,1,2,4,3,2,2,2,2,1,4,1,1,5,1,3,4,4,1,1,3,3,5,5,3,1,3,3,3,1,4,2,2,1,3,4,1,4,3,3,2,3,1,1,1,5,3,1,4,2,2,3,1,3,1,2,3,3,1,4,2,2,4,1,3,1,1,1,1,1,2,1,3,3,1,2,1,1,3,4,1,1,1,1,5,1,1,5,1,1,1,4,1,5,3,1,1,3,2,1,1,3,1,1,1,5,4,3,3,5,1,3,4,3,3,1,4,4,1,2,1,1,2,1,1,1,2,1,1,1,1,1,5,1,1,2,1,5,2,1,1,2,3,2,3,1,3,1,1,1,5,1,1,2,1,1,1,1,3,4,5,3,1,4,1,1,4,1,4,1,1,1,4,5,1,1,1,4,1,3,2,2,1,1,2,3,1,4,3,5,1,5,1,1,4,5,5,1,1,3,3,1,1,1,1,5,5,3,3,2,4,1,1,1,1,1,5,1,1,2,5,5,4,2,4,4,1,1,3,3,1,5,1,1,1,1,1,1
diff --git a/day06.bqn b/day06.bqn
new file mode 100644
index 0000000..3e1ebe1
--- /dev/null
+++ b/day06.bqn
@@ -0,0 +1,5 @@
+d←+˝(↕9)=⌜˜ •BQN '⟨'⊸∾ ∾⟜'⟩' •FChars"day06"
+Step ← 1⊸⌽ + (6=↕9)×⊑
+
+•Out +´ Step⍟80 d
+•Out +´ Step⍟256 d
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