Skip to content

Instantly share code, notes, and snippets.

@buntine
Last active December 2, 2023 22:30
Show Gist options
  • Save buntine/531b01971ff26cf9613a30fb63767143 to your computer and use it in GitHub Desktop.
Save buntine/531b01971ff26cf9613a30fb63767143 to your computer and use it in GitHub Desktop.
(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