]> www.fi.muni.cz Git - aoc.git/blobdiff - 2016/03.pl
Year 2016, days 1-10: so far pretty interesting
[aoc.git] / 2016 / 03.pl
diff --git a/2016/03.pl b/2016/03.pl
new file mode 100755 (executable)
index 0000000..ca698da
--- /dev/null
@@ -0,0 +1,32 @@
+#!/usr/bin/perl -w
+
+use strict;
+use v5.30;
+
+$; = ',';
+my %pos2num = (
+       "0,0" => 1,
+       "1,0" => 2,
+       "2,0" => 3,
+       "0,1" => 4,
+       "1,1" => 5,
+       "2,1" => 6,
+       "0,2" => 7,
+       "1,2" => 8,
+       "2,2" => 9,
+);
+my @pos = (1, 1);
+my $ret = '';
+while (<>) {
+       chomp;
+       for my $step (split //) {
+               $pos[0]-- if $pos[0] && $step eq 'L';
+               $pos[0]++ if $pos[0] < 2 && $step eq 'R';
+               $pos[1]-- if $pos[1] && $step eq 'U';
+               $pos[1]++ if $pos[1] < 2 && $step eq 'D';
+       }
+       $ret .= $pos2num{$pos[0],$pos[1]};
+}
+
+say $ret;
+