AdventOfCode/2022/day1.nim

18 lines
450 B
Nim
Raw Normal View History

2022-12-02 14:49:03 +10:30
import sequtils
import strutils
import sugar
from algorithm import sorted
2022-12-03 17:22:53 +10:30
let inputString = strip readFile "input/1"
2022-12-02 14:52:28 +10:30
let elfStrings = split(inputString, "\n\n")
let elfRations = collect newSeq:
for elf in elfStrings: collect newSeq:
for c in split elf: parseInt c
let elfCalories = collect newSeq:
2022-12-02 14:49:03 +10:30
for rations in elfRations: rations.foldl(a + b)
# Part 1
echo max elfCalories
# Part 2
2022-12-02 14:52:28 +10:30
echo elfCalories.sorted[^3 .. ^1].foldl(a + b)