23 lines
410 B
Perl
23 lines
410 B
Perl
|
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;
|