34 lines
551 B
Perl
34 lines
551 B
Perl
use 5.38.0;
|
|
|
|
package Part2;
|
|
|
|
use Part1;
|
|
|
|
use List::AllUtils qw/ sum /;
|
|
|
|
my %spelled = (
|
|
one => 1,
|
|
two => 2,
|
|
three => 3,
|
|
four => 4,
|
|
five => 5,
|
|
six => 6,
|
|
seven => 7,
|
|
eight => 8,
|
|
nine => 9,
|
|
);
|
|
|
|
sub resolve_spelled_numbers ($line) {
|
|
my $re = join '|', keys %spelled, 1 .. 9;
|
|
|
|
join "", map { $spelled{$_} // $_ } $line =~ /^.*?($re)/g,
|
|
$line =~ /^.*($re)/g;
|
|
}
|
|
|
|
sub solution_2 ($input) {
|
|
sum map { Part1::extract_number($_) }
|
|
map { resolve_spelled_numbers($_) } split "\n", $input;
|
|
}
|
|
|
|
1;
|