Last active
December 2, 2023 22:30
-
-
Save buntine/531b01971ff26cf9613a30fb63767143 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(ns advent-of-code-2023.core | |
(:require [clojure.string :refer [split split-lines]])) | |
(defn parse-line [game] | |
(let [[game-number plays] (split game #":\s") | |
play-seq (split plays #"[;,]\s")] | |
[(Integer. (re-find #"\d+" game-number)) | |
(map #(let [[n color] (split % #"\s")] | |
[(Integer. n) | |
(keyword color)]) | |
play-seq)])) | |
(defn parse-input [] | |
(->> "./resources/input.txt" | |
slurp | |
split-lines | |
(map parse-line))) | |
(defn valid-game [limits [_ plays]] | |
(every? (fn [[n color]] (<= n (limits color))) plays)) | |
(defn games-possible [& {:keys [red green blue] :as limits}] | |
(->> (parse-input) | |
(filter (partial valid-game limits)) | |
(map first) | |
(reduce +))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment