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