aboutsummaryrefslogtreecommitdiffstats
path: root/day2/solution.nim
diff options
context:
space:
mode:
authorOrfeas <38209077+0xfea5@users.noreply.github.com>2024-06-08 13:50:47 +0300
committerOrfeas <38209077+0xfea5@users.noreply.github.com>2024-06-08 13:50:47 +0300
commit7be570c4a6e86fb7060f0bc06910ca57003dfe90 (patch)
treea998f976596cb902cd8988d74f756b72660bc29c /day2/solution.nim
parentDay 21 (part1) (diff)
downloadaoc22-7be570c4a6e86fb7060f0bc06910ca57003dfe90.tar.gz
aoc22-7be570c4a6e86fb7060f0bc06910ca57003dfe90.zip
Update file names and init.shHEADmain
Diffstat (limited to 'day2/solution.nim')
-rw-r--r--day2/solution.nim51
1 files changed, 0 insertions, 51 deletions
diff --git a/day2/solution.nim b/day2/solution.nim
deleted file mode 100644
index 8a794d3..0000000
--- a/day2/solution.nim
+++ /dev/null
@@ -1,51 +0,0 @@
1import std/strutils
2import std/sequtils
3
4let content = readFile("./input.txt").strip().split("\n")
5let rounds = map(
6 content,
7 # Split line into pair of characters
8 proc(round: string): tuple[other: char, self: char] =
9 var splitted = round.split(" ")
10 (splitted[0][0], splitted[1][0]))
11
12# example: rounds = [('A', 'Z'), ('C', 'Y')]
13# echo rounds
14
15proc solve(dScore: array[3, array[3, int]]): int =
16 var score = 0
17 for round in rounds:
18 let
19 i = ord(round.other) - ord('A')
20 j = ord(round.self) - ord('X')
21 score += dScore[i][j]
22
23 return score
24
25let pt1 = [
26 # A = Rock
27 # X Y Z
28 [1 + 3, 2 + 6, 3 + 0],
29 # B = Paper
30 # X Y Z
31 [1 + 0, 2 + 3, 3 + 6],
32 # C = Scissors
33 # X Y Z
34 [1 + 6, 2 + 0, 3 + 3],
35]
36
37echo solve(pt1)
38
39let pt2 = [
40 # A = Rock
41 # X Y Z
42 [3 + 0, 1 + 3, 2 + 6],
43 # B = Paper
44 # X Y Z
45 [1 + 0, 2 + 3, 3 + 6],
46 # C = Scissors
47 # X Y Z
48 [2 + 0, 3 + 3, 1 + 6],
49]
50
51echo solve(pt2)