]> www.fi.muni.cz Git - aoc.git/blob - 2023/08.pl
Day 25: examining the input
[aoc.git] / 2023 / 08.pl
1 #!/usr/bin/perl -w
2
3 use v5.38;
4
5 my $sum;
6 my @scores;
7 while (<>) {
8         my ($have, $win) = /: (.*) \| (.*)/;
9         my %is_win = map { $_ => 1 } ($win =~ /(\d+)/g);
10         push @scores, scalar grep { $is_win{$_} } ($have =~ /(\d+)/g);
11 }
12
13 my @cards = (1) x @scores;
14 while (@scores) {
15         my $n = shift @scores;
16         my $c = shift @cards;
17         $sum += $c;
18         next if !$n;
19         $cards[$_] += $c for 0 .. $n-1;
20 }
21         
22 say $sum;