--- /dev/null
+(module net.journcy.aoc2022.day02)
+
+(defn inc [n] (+ n 1))
+(defn dec [n] (- n 1))
+(defn lines [file] (icollect [v (io.lines file)] v))
+(defn numbers [file] (icollect [v (io.lines file)] (tonumber v)))
+(defn head [tbl] (. tbl 1))
+(defn last [tbl] (let [n (# tbl)] (. tbl n)))
+(defn map [f tbl] (icollect [_ v (ipairs tbl)] (f v)))
+(defn add [a b] (+ a b))
+(defn gt [a b] (> a b))
+(defn accnum [f tbl]
+ (accumulate [acc 0
+ _ v (ipairs tbl)]
+ (f acc v)))
+(defn take [n tbl]
+ (accumulate [t []
+ i v (ipairs tbl)
+ &until (> i n)]
+ (doto t (table.insert v))))
+(defn partition [tbl brk]
+ (accumulate [parts [[]]
+ _ v (ipairs tbl)]
+ (do
+ (if (= v brk)
+ (table.insert parts [])
+ (table.insert (last parts) v))
+ parts)))
+(defn sum [tbl] (accnum add tbl))
+(defn sort [tbl f] (do (table.sort tbl f) tbl))
+
+; A: rock, B: paper, C: scissors
+; X: rock, Y: paper, Z: scissors
+(defn determine [play resp]
+ (match [play resp]
+ [:A :X] 3
+ [:A :Y] 6
+ [:A :Z] 0
+ [:B :X] 0
+ [:B :Y] 3
+ [:B :Z] 6
+ [:C :X] 6
+ [:C :Y] 0
+ [:C :Z] 3))
+
+(defn permute [sym dir]
+ (match [sym dir]
+ [:A :X] :C
+ [:B :X] :A
+ [:C :X] :B
+ [ S :Y] S
+ [:A :Z] :B
+ [:B :Z] :C
+ [:C :Z] :A))
+
+(defn score [round]
+ (let [play (string.sub round 1 1)
+ resp (string.sub round 3 3)
+ outcome (determine play resp)]
+ (+ outcome
+ (match resp :X 1 :Y 2 :Z 3))))
+
+(defn nuscore [round]
+ (let [play (string.sub round 1 1)
+ resp (string.sub round 3 3)]
+ (+ (match resp :X 0 :Y 3 :Z 6)
+ (match (permute play resp)
+ :A 1 :B 2 :C 3))))
+
+(comment
+ (score "A Y")
+ (score "B X")
+ (score "C Z")
+ (map score (take 1 (lines "input/day02.txt"))))
+
+(defn part1 [lines]
+ (->> lines
+ (map score)
+ sum))
+
+(defn part2 [lines]
+ (->> lines
+ (map nuscore)
+ sum))
+
+(comment
+ (part1 (lines "input/day02.txt"))
+ (part2 (lines "input/day02.txt")))