Last active
December 9, 2022 11:47
-
-
Save schmalz/a1281c62212c3934b50b3b024b3427ee to your computer and use it in GitHub Desktop.
Advent of Code 2022, day 2
This file contains hidden or 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 day-2.core | |
(:require [clojure.string :as str])) | |
(def rounds | |
"Return a sequence of all the rounds of the game." | |
(str/split (slurp "input.txt") | |
#"\n")) | |
(defn plan-a | |
[round] | |
(condp = round | |
"A X" (+ 1 3) | |
"A Y" (+ 2 6) | |
"A Z" (+ 3 0) | |
"B X" (+ 1 0) | |
"B Y" (+ 2 3) | |
"B Z" (+ 3 6) | |
"C X" (+ 1 6) | |
"C Y" (+ 2 0) | |
"C Z" (+ 3 3))) | |
(defn plan-b | |
[round] | |
(condp = round | |
"A X" (+ 3 0) | |
"A Y" (+ 1 3) | |
"A Z" (+ 2 6) | |
"B X" (+ 1 0) | |
"B Y" (+ 2 3) | |
"B Z" (+ 3 6) | |
"C X" (+ 2 0) | |
"C Y" (+ 3 3) | |
"C Z" (+ 1 6))) | |
(defn total-score | |
"Given a scoring PLAN, return the total score for all the ROUNDS." | |
[plan rounds] | |
(reduce + | |
(map plan rounds))) | |
(def plan-a-score | |
(total-score plan-a rounds)) | |
(def plan-b-score | |
(total-score plan-b rounds)) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment