From 9b75ff37448f9ebf28631116be6ca737b1ee6ebe Mon Sep 17 00:00:00 2001 From: Rupus Reinefjord Date: Thu, 1 Dec 2022 19:07:04 +0100 Subject: [PATCH] day 01 --- .gitignore | 2 ++ day-01/solve.nim | 19 +++++++++++++++++++ 2 files changed, 21 insertions(+) create mode 100644 .gitignore create mode 100644 day-01/solve.nim diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..d89dcc9 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +solve +input diff --git a/day-01/solve.nim b/day-01/solve.nim new file mode 100644 index 0000000..643017a --- /dev/null +++ b/day-01/solve.nim @@ -0,0 +1,19 @@ +import std/[algorithm, math, os, strutils, sugar] + +let lst = stdin.readAll().strip() + +let elves = lst.split("\n\n") + +var totals = collect: + for elf in elves: + let elfInts = collect: + for cal in elf.split("\n"): + parseInt(cal) + sum(elfInts) + +totals.sort(order = Descending) + +if paramStr(1) == "1": + echo(totals[0]) +elif paramStr(1) == "2": + echo(sum(totals[0..2]))