#!/usr/local/bin/perl # day 2022-01 use strict; use warnings; use v5.32; use List::Util qw( sum ); @ARGV = "input" unless @ARGV; chomp( my $input = do { local $/; <> } ); my @items = split /\n/, $input; my $max = 0; my $current = 0; my @top_3 = ( 0, 0, 0 ); foreach my $item ( @items ) { unless ( $item ) { $max = $current if ( $current > $max ); if ( $current > $top_3[0] ) { shift @top_3; push @top_3 => $current; @top_3 = sort { $a <=> $b } @top_3; } $current = 0; } else { $current += $item; } } # check last elf if ( $current > $top_3[0] ) { shift @top_3; push @top_3 => $current; } say "part 1: ", $max; say "part 2: ", sum @top_3;