]> www.fi.muni.cz Git - aoc.git/blobdiff - 2016/33.pl
The rest of Year 2016
[aoc.git] / 2016 / 33.pl
diff --git a/2016/33.pl b/2016/33.pl
new file mode 100755 (executable)
index 0000000..f01c253
--- /dev/null
@@ -0,0 +1,35 @@
+#!/usr/bin/perl -w
+
+use strict;
+use v5.30;
+
+use Digest::MD5 qw(md5_hex);
+my $in = 'pvhmgsws';
+
+my @paths = [ 0, 0, '' ];
+
+while (@paths) {
+       my $p = shift @paths;
+       my ($x, $y, $path) = @$p;
+
+       if ($x == 3 && $y == 3)  {
+               say $path;
+               last;
+       }
+
+       my $h = md5_hex($in.$path);
+       if ($y > 0 && substr($h, 0, 1) =~ /[b-f]/) {
+               push @paths, [ $x, $y-1, $path.'U' ];
+       }
+       if ($y < 3 && substr($h, 1, 1) =~ /[b-f]/) {
+               push @paths, [ $x, $y+1, $path.'D' ];
+       }
+       if ($x > 0 && substr($h, 2, 1) =~ /[b-f]/) {
+               push @paths, [ $x-1, $y, $path.'L' ];
+       }
+       if ($x < 3 && substr($h, 3, 1) =~ /[b-f]/) {
+               push @paths, [ $x+1, $y, $path.'R' ];
+       }
+}
+
+