]> www.fi.muni.cz Git - aoc.git/blob - 2023/02.pl
56e0c2696be023e797acb4a7f0f1b11b8fe91acc
[aoc.git] / 2023 / 02.pl
1 #!/usr/bin/perl -w
2
3 use v5.38;
4 use strict;
5 use experimental 'multidimensional', 'for_list', 'builtin';
6
7 my $sum;
8
9 my %map = (
10         one   => 1,
11         two   => 2,
12         three => 3,
13         four  => 4,
14         five  => 5,
15         six   => 6,
16         seven => 7,
17         eight => 8,
18         nine  => 9,
19 );
20
21 while (<>) {
22         my ($first) = /(\d|one|two|three|four|five|six|seven|eight|nine)/;
23         my ($last)  = /(?:.*)(\d|one|two|three|four|five|six|seven|eight|nine)/;
24         $first = $map{$first} if exists $map{$first};
25         $last =  $map{$last}  if exists $map{$last};
26         $sum += "$first$last";
27         # say "$_ $first $last.";
28 }
29
30 say $sum;