50 lines
940 B
Perl
50 lines
940 B
Perl
use 5.38.0;
|
|
|
|
use Test2::V0;
|
|
|
|
use Path::Tiny;
|
|
|
|
use Part1;
|
|
use Part2;
|
|
|
|
my $input = path('input')->slurp;
|
|
|
|
my %sample = (
|
|
'1abc2' => 12,
|
|
pqr3stu8vwx => 38,
|
|
a1b2c3d4e5f => 15,
|
|
treb7uchet => 77
|
|
);
|
|
|
|
for my ( $line, $expected ) (%sample) {
|
|
is Part1::extract_number($line) => $expected;
|
|
}
|
|
|
|
is Part1::solution_1($input) => 56397;
|
|
|
|
subtest 'part 2' => sub {
|
|
|
|
is Part2::resolve_spelled_numbers("sixsixsix") => 66;
|
|
|
|
%sample = (
|
|
'two1nine' => 29,
|
|
eightwothree => 83,
|
|
abcone2threexyz => 13,
|
|
xtwone3four => 24,
|
|
'4nineeightseven2' => 42,
|
|
zoneight234 => 14,
|
|
'7pqrstsixteen' => 76,
|
|
'twothreefour' => 24,
|
|
);
|
|
|
|
for my ( $line, $expected ) (%sample) {
|
|
is Part1::extract_number( Part2::resolve_spelled_numbers($line) ) =>
|
|
$expected;
|
|
}
|
|
|
|
is Part2::solution_2($input) => 55701;
|
|
|
|
};
|
|
|
|
done_testing;
|