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