feat: day 2 part 1
This commit is contained in:
parent
9280405f8f
commit
90fe696ca4
@ -4,7 +4,7 @@
|
|||||||
[utils]
|
[utils]
|
||||||
[clojure.string :as str]))
|
[clojure.string :as str]))
|
||||||
|
|
||||||
(def contents ":: String" (utils/read-file "02" true))
|
(def contents ":: String" (utils/read-file "02" false))
|
||||||
(def lines ":: Vector of String" (str/split-lines contents))
|
(def lines ":: Vector of String" (str/split-lines contents))
|
||||||
|
|
||||||
; cubes: red, green, blue
|
; cubes: red, green, blue
|
||||||
@ -55,11 +55,27 @@
|
|||||||
game-sections-vec (map parse-single-game game-sections)]
|
game-sections-vec (map parse-single-game game-sections)]
|
||||||
{:id game-id :games game-sections-vec}))
|
{:id game-id :games game-sections-vec}))
|
||||||
|
|
||||||
|
(defn game-possible?
|
||||||
|
":: Game -> Boolean
|
||||||
|
|
||||||
|
Checks if `game` is possible with the given color counts."
|
||||||
|
[game red-count green-count blue-count]
|
||||||
|
; next-game :: {:red Int :green Int :blue Int}
|
||||||
|
(nil? (utils/find-first (fn [next-game]
|
||||||
|
; find the first game that couldnt be possible
|
||||||
|
(or
|
||||||
|
(< red-count (next-game :red 0))
|
||||||
|
(< green-count (next-game :green 0))
|
||||||
|
(< blue-count (next-game :blue 0))))
|
||||||
|
(game :games))))
|
||||||
|
|
||||||
(defn part1
|
(defn part1
|
||||||
":: () -> String"
|
":: () -> String"
|
||||||
[]
|
[]
|
||||||
(let [count (map parse-game lines)]
|
(let [games (map parse-game lines)
|
||||||
(str "count: " count)))
|
possible-games (filter (fn [game] (game-possible? game 12 13 14)) games)
|
||||||
|
possible-games-sum (reduce #(+ %1 (%2 :id)) 0 possible-games)]
|
||||||
|
(str possible-games-sum)))
|
||||||
|
|
||||||
(defn part2
|
(defn part2
|
||||||
":: () -> String"
|
":: () -> String"
|
||||||
|
Loading…
Reference in New Issue
Block a user