File tree Expand file tree Collapse file tree 1 file changed +35
-0
lines changed
src/advent_of_clojure/2022 Expand file tree Collapse file tree 1 file changed +35
-0
lines changed Original file line number Diff line number Diff line change
1
+ (ns advent-of-clojure.2022.02
2
+ (:require [clojure.string :as str]))
3
+
4
+ (def input (partition 2 (-> " resources/2022/02.dat" slurp (str/split #"\s +" ))))
5
+
6
+ ; ; You can probably do some smart shifting here
7
+ (def draw {" A" " X" , " B" " Y" , " C" " Z" })
8
+ (def beats {" A" " Y" , " B" " Z" , " C" " X" })
9
+ (def loses-to {" A" " Z" , " B" " X" , " C" " Y" })
10
+
11
+ (defn outcome [opponent you]
12
+ (cond (= (draw opponent) you) 3
13
+ (= (beats opponent) you) 6
14
+ :else 0 ))
15
+
16
+ (def value {" X" 1 , " Y" 2 , " Z" 3 })
17
+
18
+ (defn score [[opponent you]]
19
+ (+ (value you) (outcome opponent you)))
20
+
21
+ (def part-one (->> input (map score) (reduce +)))
22
+
23
+ (defn move [opponent outcome]
24
+ (case outcome
25
+ " X" (loses-to opponent)
26
+ " Y" (draw opponent)
27
+ " Z" (beats opponent)))
28
+
29
+ (def points {" X" 0 " Y" 3 " Z" 6 })
30
+
31
+ (defn final-score [[opponent outcome]]
32
+ (+ (value (move opponent outcome))
33
+ (points outcome)))
34
+
35
+ (def part-two (->> input (map final-score) (reduce +)))
You can’t perform that action at this time.
0 commit comments