aboutsummaryrefslogtreecommitdiff
path: root/2022/nim/day02/src
diff options
context:
space:
mode:
authorj-james2022-12-03 02:39:47 +0000
committerj-james2022-12-03 02:39:47 +0000
commitf5f940c52b38a5e17092f5896dc2fc13e8443478 (patch)
tree433ebcfee2ea54432734b44d8f51f95fc5ac8a69 /2022/nim/day02/src
parent13b3ae4211631c74b9249a6033869f75e036fad2 (diff)
Day Two
Diffstat (limited to '2022/nim/day02/src')
-rw-r--r--2022/nim/day02/src/main.nim42
1 files changed, 42 insertions, 0 deletions
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