-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathday_06.clj
28 lines (24 loc) · 1020 Bytes
/
day_06.clj
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
(ns day_06
(:require [utils :refer [map-keys map-vals open-resource parse-int split-by-comma]]))
(def input-file "day_06.txt")
(def data (->> input-file open-resource first split-by-comma (map parse-int)))
(defn part-01 [input days]
(let [merge-overlapping-ages (fn [m]
(merge-with +
(dissoc m -1)
{6 (get m -1 0)
8 (get m -1 0)}))]
(loop [fish (->> input
(group-by identity)
(map-vals count))
day 1]
(let [updated-fish (->> fish
(map-keys dec)
merge-overlapping-ages)]
(if (< day days)
(recur updated-fish (inc day))
(->> updated-fish vals (reduce +)))))))
(defn -main [& _]
(println "Day 06:")
(println "\t-> Part 1: " (part-01 data 80))
(println "\t-> Part 2: " (part-01 data 256)))