]> www.fi.muni.cz Git - aoc.git/blob - 2016/36.pl
Day 25: examining the input
[aoc.git] / 2016 / 36.pl
1 #!/usr/bin/perl -w
2
3 use strict;
4 use v5.30;
5
6 chomp (my $line = <>);
7
8 my $traps;
9 for (1 .. 400000) {
10         $traps += () = $line =~ /\./g;
11         say $traps if $_ == 400000;
12         $line = '.' . $line . '.';
13         my $nl = '';
14         for my $i (0 .. length($line)-3) {
15                 my $p = substr($line, $i, 3);
16                 $nl .= ($p eq '^^.' || $p eq '.^^' || $p eq '^..' || $p eq '..^')
17                         ? '^' : '.';
18         }
19         # say "$_ $nl";
20         $line = $nl;
21 }
22