Economize parens in Nim as a joke

This commit is contained in:
Luke Hubmayer-Werner 2022-12-02 14:52:28 +10:30
parent 4c6785b4fd
commit 84ef9a5343
1 changed files with 6 additions and 6 deletions

View File

@ -4,14 +4,14 @@ 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):
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:
for rations in elfRations: rations.foldl(a + b)
# Part 1
echo max elfCalories
# Part 2
echo elfCalories.sorted()[^3 .. ^1].foldl(a + b)
echo elfCalories.sorted[^3 .. ^1].foldl(a + b)