]> www.fi.muni.cz Git - aoc.git/blobdiff - 2015/06.pl
Year 2015
[aoc.git] / 2015 / 06.pl
diff --git a/2015/06.pl b/2015/06.pl
new file mode 100755 (executable)
index 0000000..9980eb1
--- /dev/null
@@ -0,0 +1,25 @@
+#!/usr/bin/perl -w
+
+use v5.16;
+use strict;
+
+$_ = <>;
+
+my @x = (0, 0);
+my @y = (0, 0);
+$; = ',';
+my %seen = ("0,0" => 1);
+
+my $s = 0;
+for my $v (split //) {
+       $x[$s]++ if $v eq '>';
+       $y[$s]++ if $v eq 'v';
+       $x[$s]-- if $v eq '<';
+       $y[$s]-- if $v eq '^';
+       $seen{$x[$s],$y[$s]}++;
+       $s = 1-$s;
+}
+
+say scalar keys %seen;
+       
+