aboutsummaryrefslogtreecommitdiffstats
path: root/day4
diff options
context:
space:
mode:
authorClyne Sullivan <clyne@bitgloo.com>2022-11-30 19:55:31 -0500
committerClyne Sullivan <clyne@bitgloo.com>2022-11-30 19:55:31 -0500
commit8d43e37df99f280377bed90284d6ac2428334804 (patch)
tree3a5042c9af29da52b4bac38fd78b3ccde77a1dbc /day4
parent66ed0b9d27850dc653abc8baa75884f3de311bfa (diff)
move 2021 days to folder; update README
Diffstat (limited to 'day4')
-rw-r--r--day4/part1.clj70
-rw-r--r--day4/part2.clj70
2 files changed, 0 insertions, 140 deletions
diff --git a/day4/part1.clj b/day4/part1.clj
deleted file mode 100644
index b9fcceb..0000000
--- a/day4/part1.clj
+++ /dev/null
@@ -1,70 +0,0 @@
-(require '[clojure.string :as str])
-
-(def calls
- (->> (read-line)
- (#(str/split % #","))
- (map #(Integer/parseInt %))
- )
- )
-
-(defn read-board []
- (when (some? (read-line))
- (mapv
- (fn [line] (->> line
- (str/join)
- (str/trim)
- (#(str/split % #"\s+"))
- (map #(Integer/parseInt %))
- )
- )
- (repeatedly 5 read-line)
- )
- )
- )
-
-(defn bingo? [board]
- (some?
- (some
- #(every? nil? %)
- (concat board (apply mapv vector board))
- )
- )
- )
-
-(defn bingo-mark [board n]
- (mapv (partial replace {n nil}) board)
- )
-
-(defn get-bingo [init-board]
- (loop [board init-board nums calls turns 1]
- (let [new-board (bingo-mark board (first nums))]
- (if (bingo? new-board)
- [new-board (first nums) turns]
- (recur new-board (rest nums) (inc turns))
- )
- )
- )
- )
-
-(loop [best [999 0] board (read-board)]
- (if (nil? board)
- (println best)
- (let [bingo (get-bingo board)]
- (recur
- (if (< (get bingo 2) (first best))
- [(get bingo 2)
- (->> (first bingo)
- (flatten)
- (filter some?)
- (apply +)
- (* (second bingo))
- )
- ]
- best
- )
- (read-board)
- )
- )
- )
- )
-
diff --git a/day4/part2.clj b/day4/part2.clj
deleted file mode 100644
index 516e83c..0000000
--- a/day4/part2.clj
+++ /dev/null
@@ -1,70 +0,0 @@
-(require '[clojure.string :as str])
-
-(def calls
- (->> (read-line)
- (#(str/split % #","))
- (map #(Integer/parseInt %))
- )
- )
-
-(defn read-board []
- (when (some? (read-line))
- (mapv
- (fn [line] (->> line
- (str/join)
- (str/trim)
- (#(str/split % #"\s+"))
- (map #(Integer/parseInt %))
- )
- )
- (repeatedly 5 read-line)
- )
- )
- )
-
-(defn bingo? [board]
- (some?
- (some
- #(every? nil? %)
- (concat board (apply mapv vector board))
- )
- )
- )
-
-(defn bingo-mark [board n]
- (mapv (partial replace {n nil}) board)
- )
-
-(defn get-bingo [init-board]
- (loop [board init-board nums calls turns 1]
- (let [new-board (bingo-mark board (first nums))]
- (if (bingo? new-board)
- [new-board (first nums) turns]
- (recur new-board (rest nums) (inc turns))
- )
- )
- )
- )
-
-(loop [best [0 0] board (read-board)]
- (if (nil? board)
- (println best)
- (let [bingo (get-bingo board)]
- (recur
- (if (> (get bingo 2) (first best))
- [(get bingo 2)
- (->> (first bingo)
- (flatten)
- (filter some?)
- (apply +)
- (* (second bingo))
- )
- ]
- best
- )
- (read-board)
- )
- )
- )
- )
-