]> www.fi.muni.cz Git - aoc.git/blobdiff - 2016/16.pl
Year 2016, days 1-10: so far pretty interesting
[aoc.git] / 2016 / 16.pl
diff --git a/2016/16.pl b/2016/16.pl
new file mode 100755 (executable)
index 0000000..4e68ebe
--- /dev/null
@@ -0,0 +1,41 @@
+#!/usr/bin/perl -w
+
+use strict;
+use v5.30;
+
+my %screen;
+my ($w, $h) = (50, 6);
+$; = ',';
+
+while (<>) {
+       if (/rect (\d+)x(\d+)/) {
+               for my $x (0 .. $1-1) {
+               for my $y (0 .. $2-1) {
+                       $screen{$x,$y} = 1;
+               } }
+       } elsif (/rotate row y=(\d+) by (\d+)/) {
+               my %ns = %screen;
+               for my $x (0 .. $w-1) {
+                       my $sx = $x - $2;
+                       $sx += $w if $sx < 0;
+                       $ns{$x,$1} = $screen{$sx,$1};
+               }
+               %screen = %ns;
+       } elsif (/rotate column x=(\d+) by (\d+)/) {
+               my %ns = %screen;
+               for my $y (0 .. $h-1) {
+                       my $sy = $y - $2;
+                       $sy += $h if $sy < 0;
+                       $ns{$1,$y} = $screen{$1,$sy};
+               }
+               %screen = %ns;
+       }
+}
+
+for my $y (0 .. $h-1) {
+       for my $x (0 .. $w-1) {
+               print $screen{$x,$y} ? '#' : ' ';
+       }
+       print "\n";
+}
+