]> www.fi.muni.cz Git - aoc2020.git/blobdiff - 47.pl
Day 24 - nice!
[aoc2020.git] / 47.pl
diff --git a/47.pl b/47.pl
new file mode 100755 (executable)
index 0000000..fca227f
--- /dev/null
+++ b/47.pl
@@ -0,0 +1,29 @@
+#!/usr/bin/perl -w
+
+use strict;
+
+my %tiles;
+
+while (<>) {
+       chomp;
+       my ($x, $y) = (0, 0);
+       while (length) {
+               s/\A(se|ne|sw|nw|e|w)//;
+               if ($1 eq 'ne') {
+                       $y++;
+               } elsif ($1 eq 'e') {
+                       $x++;
+               } elsif ($1 eq 'se') {
+                       $x++; $y--;
+               } elsif ($1 eq 'sw') {
+                       $y--;
+               } elsif ($1 eq 'w') {
+                       $x--;
+               } elsif ($1 eq 'nw') {
+                       $x--; $y++;
+               }
+       }
+       $tiles{"$x|$y"}++;
+}
+
+print "Tiles=" . (grep { $tiles{$_} % 2 == 1 } keys %tiles)."\n";