adventofcode/2024/01/Part1.pm

23 lines
410 B
Perl
Raw Permalink Normal View History

2024-12-04 20:46:05 +00:00
package Day1::Part1;
use 5.36.0;
use List::Util qw/ sum pairmap /;
use List::MoreUtils qw/ part zip /;
sub read_file(@lines) {
my $i = 0;
my @lists = part { $i++ % 2} map { split } @lines;
return @lists;
}
sub solve(@lists) {
for my $x (1,0) {
$lists[$x] = [ sort { $a <=> $b } $lists[$x]->@* ];
}
return sum pairmap { abs $a - $b } zip $lists[0]->@*, $lists[1]->@*;
}
1;