2022 Day 1 Nim
This commit is contained in:
parent
d8f1d27bd7
commit
4c6785b4fd
|
@ -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)
|
Loading…
Reference in New Issue