]> www.fi.muni.cz Git - aoc.git/blob - 2016/04.pl
Day 25: examining the input
[aoc.git] / 2016 / 04.pl
1 #!/usr/bin/perl -w
2
3 use strict;
4 use v5.30;
5
6 $; = ',';
7 my %pos2num = (
8         "2,0" => 1,
9         "1,1" => 2,
10         "2,1" => 3,
11         "3,1" => 4,
12         "0,2" => 5,
13         "1,2" => 6,
14         "2,2" => 7,
15         "3,2" => 8,
16         "4,2" => 9,
17         "1,3" => 'A',
18         "2,3" => 'B',
19         "3,3" => 'C',
20         "2,4" => 'D',
21 );
22 my @pos = (0, 2);
23 my $ret = '';
24 while (<>) {
25         chomp;
26         for my $step (split //) {
27                 $pos[0]-- if $pos2num{ ($pos[0]-1).",$pos[1]" } && $step eq 'L';
28                 $pos[0]++ if $pos2num{ ($pos[0]+1).",$pos[1]" } && $step eq 'R';
29                 $pos[1]-- if $pos2num{ "$pos[0],".($pos[1]-1) } && $step eq 'U';
30                 $pos[1]++ if $pos2num{ "$pos[0],".($pos[1]+1) } && $step eq 'D';
31         }
32         $ret .= $pos2num{$pos[0],$pos[1]};
33 }
34
35 say $ret;
36