aboutsummaryrefslogtreecommitdiff
path: root/2022/nim
diff options
context:
space:
mode:
authorj-james2022-12-01 06:48:57 +0000
committerj-james2022-12-01 06:48:57 +0000
commit926b0949d12588641f29836a6e41712b3237b1b9 (patch)
tree94131d556f67f847de3ad64ae4fdae37ae4888be /2022/nim
parent6a3c52602974d411c99b312d9ae709e53ef0e29c (diff)
Day One
Diffstat (limited to '2022/nim')
-rw-r--r--2022/nim/day01/src/main.nim11
1 files changed, 11 insertions, 0 deletions
diff --git a/2022/nim/day01/src/main.nim b/2022/nim/day01/src/main.nim
new file mode 100644
index 0000000..ebdd5e7
--- /dev/null
+++ b/2022/nim/day01/src/main.nim
@@ -0,0 +1,11 @@
+# Day One: Calorie Counting
+import std/[os, strutils, sequtils, algorithm]
+
+let input: seq[seq[int]] = paramStr(1).readFile().strip().split("\n\n")
+ .mapIt(it.strip().split("\n").map(parseInt))
+
+let elves = input.mapIt(it.foldl(a+b, 0))
+echo elves.foldl(max(a,b), 0)
+
+let sorted = elves.sorted(cmp[int], Descending)
+echo sorted[0] + sorted[1] + sorted[2]