This commit is contained in:
Yanick Champoux 2018-02-25 13:58:41 -05:00
parent 6688ba464b
commit b342b3783a
2 changed files with 86 additions and 0 deletions

43
2016/17/1.pl Normal file
View File

@ -0,0 +1,43 @@
use 5.20.0;
use Digest::MD5 qw/ md5_hex /;
use Math::Vector::Real;
use List::AllUtils qw/ min max minmax /;
my @directions = (
[ 'U', V(0,-1) ],
[ 'D', V(0,1) ],
[ 'L', V(-1,0) ],
[ 'R', V(1,0) ],
);
my $best_path;
wander( 'bwnlcvfs', V(0,0) );
sub wander {
my( $hash, $c ) = @_;
if( $best_path and length($hash) >= length($best_path) ) {
return;
}
my( $min,$max ) = minmax @$c;
return if 0 > $min;
return if 3 < $max;
if( $c == V(3,3) ) {
$best_path = $hash;
say $best_path;
return;
}
my @md5 = split '', md5_hex($hash), 5;
my @d = grep { (shift @md5) =~ /[b-f]/ } @directions;
for my $d ( @d ) {
wander( $hash . $d->[0], $c + $d->[1] );
}
}

43
2016/17/2.pl Normal file
View File

@ -0,0 +1,43 @@
use 5.20.0;
use Digest::MD5 qw/ md5_hex /;
use Math::Vector::Real;
use List::AllUtils qw/ min max minmax /;
my @directions = (
[ 'U', V(0,-1) ],
[ 'D', V(0,1) ],
[ 'L', V(-1,0) ],
[ 'R', V(1,0) ],
);
my $best_path;
wander( 'bwnlcvfs', V(0,0) );
say length($best_path) - 8;
sub wander {
my( $hash, $c ) = @_;
my( $min,$max ) = minmax @$c;
return if 0 > $min;
return if 3 < $max;
if( $c == V(3,3) ) {
say $hash;
if( length($hash) >= length($best_path) ) {
$best_path = $hash;
}
return;
}
my @md5 = split '', md5_hex($hash), 5;
my @d = grep { (shift @md5) =~ /[b-f]/ } @directions;
for my $d ( @d ) {
wander( $hash . $d->[0], $c + $d->[1] );
}
}