]> www.fi.muni.cz Git - aoc.git/blobdiff - 2016/35.pl
The rest of Year 2016
[aoc.git] / 2016 / 35.pl
diff --git a/2016/35.pl b/2016/35.pl
new file mode 100755 (executable)
index 0000000..5dc4a09
--- /dev/null
@@ -0,0 +1,22 @@
+#!/usr/bin/perl -w
+
+use strict;
+use v5.30;
+
+chomp (my $line = <>);
+
+my $traps;
+for (1 .. 40) {
+       $traps += () = $line =~ /\./g;
+       say $traps;
+       $line = '.' . $line . '.';
+       my $nl = '';
+       for my $i (0 .. length($line)-3) {
+               my $p = substr($line, $i, 3);
+               $nl .= ($p eq '^^.' || $p eq '.^^' || $p eq '^..' || $p eq '..^')
+                       ? '^' : '.';
+       }
+       say "$_ $nl";
+       $line = $nl;
+}
+