]> www.fi.muni.cz Git - aoc2020.git/blob - 47.pl
Task 9 Perl Golf-style
[aoc2020.git] / 47.pl
1 #!/usr/bin/perl -w
2
3 use strict;
4
5 my %tiles;
6
7 while (<>) {
8         chomp;
9         my ($x, $y) = (0, 0);
10         while (length) {
11                 s/\A(se|ne|sw|nw|e|w)//;
12                 if ($1 eq 'ne') {
13                         $y++;
14                 } elsif ($1 eq 'e') {
15                         $x++;
16                 } elsif ($1 eq 'se') {
17                         $x++; $y--;
18                 } elsif ($1 eq 'sw') {
19                         $y--;
20                 } elsif ($1 eq 'w') {
21                         $x--;
22                 } elsif ($1 eq 'nw') {
23                         $x--; $y++;
24                 }
25         }
26         $tiles{"$x|$y"}++;
27 }
28
29 print "Tiles=" . (grep { $tiles{$_} % 2 == 1 } keys %tiles)."\n";