]> code.bitgloo.com Git - clyne/advent-of-code.git/commitdiff
add day 6
authorClyne Sullivan <clyne@bitgloo.com>
Mon, 6 Dec 2021 13:40:44 +0000 (08:40 -0500)
committerClyne Sullivan <clyne@bitgloo.com>
Mon, 6 Dec 2021 13:40:44 +0000 (08:40 -0500)
day6/part1.clj [new file with mode: 0644]
day6/part2.clj [new file with mode: 0644]

diff --git a/day6/part1.clj b/day6/part1.clj
new file mode 100644 (file)
index 0000000..70293f7
--- /dev/null
@@ -0,0 +1,20 @@
+(require '[clojure.string :as str])
+
+(def fish-init
+  (->> (read-line)
+       (#(str/split % #","))
+       (map #(Integer/parseInt %))
+       (vec)
+       )
+  )
+
+(defn cycle-day [fish]
+  (flatten
+    (for [f (map dec fish)]
+      (if (neg? f) [6 8] f)
+      )
+    )
+  )
+
+(println (count (nth (iterate cycle-day fish-init) 80)))
+
diff --git a/day6/part2.clj b/day6/part2.clj
new file mode 100644 (file)
index 0000000..cdcc3b5
--- /dev/null
@@ -0,0 +1,25 @@
+(require '[clojure.string :as str])
+
+(->> (read-line)
+     (#(str/split % #","))
+     (map #(Integer/parseInt %))
+     (reduce #(update %1 %2 inc) (vec (repeat 9 0)))
+     (iterate
+       #(let [nf (conj (vec (rest %)) (first %))]
+          (update nf 6 (partial + (get nf 8)))
+          )
+       )
+     (#(nth % 256))
+     (apply +)
+     (println)
+     )
+
+; ->> read input from stdin
+;     split input string by commas
+;     convert string array into number array
+;     reduce to frequency counts
+;     create iterator that returns next day's counts
+;     get 256th iteration
+;     sum all frequency counts
+;     print results
+