29 lines
844 B
Fennel
29 lines
844 B
Fennel
(io.input "input")
|
|
|
|
; rock, paper, scissors
|
|
(local own-scores-1 {:X 1 :Y 2 :Z 3})
|
|
(local game-scores {:X {:A 3 :B 0 :C 6}
|
|
:Y {:A 6 :B 3 :C 0}
|
|
:Z {:A 0 :B 6 :C 3}})
|
|
|
|
; lose, draw, win
|
|
(local own-scores-2 {:X 0 :Y 3 :Z 6})
|
|
(local game-moves {:X {:A 3 :B 1 :C 2}
|
|
:Y {:A 1 :B 2 :C 3}
|
|
:Z {:A 2 :B 3 :C 1}})
|
|
|
|
(var score-1 0)
|
|
(var score-2 0)
|
|
|
|
(each [line (io.lines)]
|
|
(let [(other you) (string.match line "(%a+) (%a)")
|
|
move-score (. own-scores-1 you)
|
|
round-score (. (. game-scores you) other)
|
|
own-score-2 (. own-scores-2 you)
|
|
move-score-2 (. (. game-moves you) other)]
|
|
(set score-1 (+ score-1 move-score round-score))
|
|
(set score-2 (+ score-2 own-score-2 move-score-2))))
|
|
|
|
(print "part 1" score-1)
|
|
(print "part 2" score-2)
|