]> www.fi.muni.cz Git - aoc.git/blob - 2023/28.pl
Day 25: examining the input
[aoc.git] / 2023 / 28.pl
1 #!/usr/bin/perl -w
2
3 use v5.38;
4
5 my $map; { local $/; $map = <>; }
6
7 my (@score, %seen, $round);
8 while (!$seen{$map}) {
9         $seen{$map} = $round++;
10         for (1 .. 4) {
11                 my $map1;
12                 do { # rotate the map:
13                         $map1 .= join('', reverse $map =~ /^./gm) . "\n"
14                 } while $map =~ s/^.//gm;
15                 chomp ($map = $map1);
16                 1 while $map =~ s/O(\.+)/$1O/g; # move O's to the right
17         }
18         $score[$round] +=()= substr($map, pos($map)) =~ /\n/g
19                 while $map =~ /O/g;
20 }
21
22 my $remains = (1000000000 - $round) % ($round - $seen{$map});
23 say $score[$seen{$map} + $remains];