From f5f940c52b38a5e17092f5896dc2fc13e8443478 Mon Sep 17 00:00:00 2001 From: j-james Date: Fri, 2 Dec 2022 18:39:47 -0800 Subject: Day Two --- 2022/nim/day02/src/main.nim | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 2022/nim/day02/src/main.nim (limited to '2022/nim/day02') diff --git a/2022/nim/day02/src/main.nim b/2022/nim/day02/src/main.nim new file mode 100644 index 0000000..c26789a --- /dev/null +++ b/2022/nim/day02/src/main.nim @@ -0,0 +1,42 @@ +# Day Two: Rock Paper Scissors +import std/[os, strutils, sequtils] + +let input = paramStr(1).readFile().strip().split("\n").mapIt(it.split(" ")) + +var score = 0 +for line in input: + if line[1] == "X": + score += 1 + if line[0] == "A": score += 3 + if line[0] == "B": score += 0 + if line[0] == "C": score += 6 + if line[1] == "Y": + score += 2 + if line[0] == "A": score += 6 + if line[0] == "B": score += 3 + if line[0] == "C": score += 0 + if line[1] == "Z": + score += 3 + if line[0] == "A": score += 0 + if line[0] == "B": score += 6 + if line[0] == "C": score += 3 +echo score + +score = 0 +for line in input: + if line[1] == "X": + score += 0 + if line[0] == "A": score += 3 + if line[0] == "B": score += 1 + if line[0] == "C": score += 2 + if line[1] == "Y": + score += 3 + if line[0] == "A": score += 1 + if line[0] == "B": score += 2 + if line[0] == "C": score += 3 + if line[1] == "Z": + score += 6 + if line[0] == "A": score += 2 + if line[0] == "B": score += 3 + if line[0] == "C": score += 1 +echo score -- cgit v1.2.3-70-g09d2