more flat files

This commit is contained in:
Rupus Reinefjord 2022-12-04 12:41:58 +01:00
parent 46a919fb8d
commit 65b4fbf539
5 changed files with 0 additions and 0 deletions

39
2022/day02.nim Normal file
View file

@ -0,0 +1,39 @@
import std/[strutils, sugar, tables]
type
Shape = ref object
loses: Shape
beats: Shape
score: int
let rock = Shape(score: 1)
let paper = Shape(beats: rock, score: 2)
rock.loses = paper
let scissors = Shape(loses: rock, beats: paper, score: 3)
rock.beats = scissors
paper.loses = scissors
let charToMove =
{ "A": rock
, "B": paper
, "C": scissors
, "X": rock
, "Y": paper
, "Z": scissors
}.toTable
let input = readAll(stdin).strip().split('\n')
let rounds = collect:
for game in input:
let s = game.split(' ')
(charToMove[s[0]], charToMove[s[1]])
var score = 0
for (opponent, me) in rounds:
score += me.score
if me.beats == opponent:
score += 6
elif me == opponent:
score += 3
echo score