]> www.fi.muni.cz Git - aoc.git/blob - 2016/33.pl
Day 25: examining the input
[aoc.git] / 2016 / 33.pl
1 #!/usr/bin/perl -w
2
3 use strict;
4 use v5.30;
5
6 use Digest::MD5 qw(md5_hex);
7 my $in = 'pvhmgsws';
8
9 my @paths = [ 0, 0, '' ];
10
11 while (@paths) {
12         my $p = shift @paths;
13         my ($x, $y, $path) = @$p;
14
15         if ($x == 3 && $y == 3)  {
16                 say $path;
17                 last;
18         }
19
20         my $h = md5_hex($in.$path);
21         if ($y > 0 && substr($h, 0, 1) =~ /[b-f]/) {
22                 push @paths, [ $x, $y-1, $path.'U' ];
23         }
24         if ($y < 3 && substr($h, 1, 1) =~ /[b-f]/) {
25                 push @paths, [ $x, $y+1, $path.'D' ];
26         }
27         if ($x > 0 && substr($h, 2, 1) =~ /[b-f]/) {
28                 push @paths, [ $x-1, $y, $path.'L' ];
29         }
30         if ($x < 3 && substr($h, 3, 1) =~ /[b-f]/) {
31                 push @paths, [ $x+1, $y, $path.'R' ];
32         }
33 }
34
35