X-Git-Url: https://www.fi.muni.cz/~kas/git//home/kas/public_html/git/?a=blobdiff_plain;f=2023%2F18.pl;h=1ea75534d67e350795caff93b03a51897714a5ed;hb=4eaa410b226684b5ff5430fc4cef481f7083a36b;hp=f41b7b1ed52f85f599398fa708eb45ca46b625d1;hpb=c5060bdbc898139cea04423a11650446d3a291a3;p=aoc.git diff --git a/2023/18.pl b/2023/18.pl index f41b7b1..1ea7553 100755 --- a/2023/18.pl +++ b/2023/18.pl @@ -1,23 +1,19 @@ #!/usr/bin/perl -w use v5.38; +use List::Util qw(sum); my $sum; while (<>) { - my @seq = /-?\d+/g; + my @seq = reverse /-?\d+/g; my @rest; while (grep $_, @seq) { - push @rest, $seq[0]; for my $i (0 .. $#seq-1) { $seq[$i] = $seq[$i+1]-$seq[$i]; } - pop @seq; + push @rest, pop @seq; } - my $s = 0; - for (reverse @rest) { - $s = $_ - $s; - } - $sum += $s; + $sum += sum @rest; } say $sum;