Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/perl
- use v5.16;
- use warnings;
- my %table = ('one' => 1, 'two' => 2, 'three' => 3, 'four' => 4, 'five' => 5,
- 'six' => 6, 'seven' => 7, 'eight' => 8, 'nine' => 9,
- map { $_ => $_ } (1 .. 9));
- my $part2 = 0;
- foreach (<>) {
- # first match
- m#(one|two|three|four|five|six|seven|eight|nine|\d)#;
- $part2 += 10 * $table{$1};
- # match with longest .* before
- m#^.*(one|two|three|four|five|six|seven|eight|nine|\d)#;
- $part2 += $table{$1};
- }
- say "Part 2: $part2";
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement