From ea271f2e9a53ad308f37019f36809568a15426dd Mon Sep 17 00:00:00 2001 From: Sijmen Date: Thu, 1 Dec 2022 15:53:39 +0100 Subject: [PATCH] day01: Only sort elves once --- day01.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/day01.rb b/day01.rb index d2ccb42..94affcd 100644 --- a/day01.rb +++ b/day01.rb @@ -1,5 +1,5 @@ input = STDIN.read.split "\n\n" -elves = input.map { |elf| elf.split("\n").map(&:to_i).sum } +elves = input.map { |elf| elf.split("\n").map(&:to_i).sum }.sort -puts "Part 1: #{elves.max}" -puts "Part 2: #{elves.sort.last(3).sum}" +puts "Part 1: #{elves.last}" +puts "Part 2: #{elves.last(3).sum}"