From 4c6785b4fdd1575363d8ed8f103d287b259d6647 Mon Sep 17 00:00:00 2001 From: Luke Hubmayer-Werner Date: Fri, 2 Dec 2022 14:49:03 +1030 Subject: [PATCH] 2022 Day 1 Nim --- 2022/day1.nim | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 2022/day1.nim diff --git a/2022/day1.nim b/2022/day1.nim new file mode 100644 index 0000000..2dc5a51 --- /dev/null +++ b/2022/day1.nim @@ -0,0 +1,17 @@ +import sequtils +import strutils +import sugar +from algorithm import sorted + +let inputString = strip readFile "day1-input" +let elfStrings = inputString.split("\n\n") +let elfRations = collect(newSeq): + for elf in elfStrings: collect(newSeq): + for c in elf.split(): parseInt(c) +let elfCalories = collect(newSeq): + for rations in elfRations: rations.foldl(a + b) + +# Part 1 +echo max elfCalories +# Part 2 +echo elfCalories.sorted()[^3 .. ^1].foldl(a + b)