aboutsummaryrefslogtreecommitdiff
path: root/challenge-118/james-smith
diff options
context:
space:
mode:
authordrbaggy <js5@sanger.ac.uk>2021-06-22 06:43:23 +0100
committerdrbaggy <js5@sanger.ac.uk>2021-06-22 06:43:23 +0100
commitc4edea73d47e0c5cd16b504e43f9e64d12cf60a2 (patch)
tree59e73b04c380545456810da0f88a015d4d1d2817 /challenge-118/james-smith
parent78a1baea42565debab6719d9bcab545328668c4f (diff)
downloadperlweeklychallenge-club-c4edea73d47e0c5cd16b504e43f9e64d12cf60a2.tar.gz
perlweeklychallenge-club-c4edea73d47e0c5cd16b504e43f9e64d12cf60a2.tar.bz2
perlweeklychallenge-club-c4edea73d47e0c5cd16b504e43f9e64d12cf60a2.zip
Tidied up output
Diffstat (limited to 'challenge-118/james-smith')
-rw-r--r--challenge-118/james-smith/perl/ch-2.pl19
1 files changed, 11 insertions, 8 deletions
diff --git a/challenge-118/james-smith/perl/ch-2.pl b/challenge-118/james-smith/perl/ch-2.pl
index a9d91e32f4..0fbfd7f130 100644
--- a/challenge-118/james-smith/perl/ch-2.pl
+++ b/challenge-118/james-smith/perl/ch-2.pl
@@ -33,7 +33,11 @@ $sol |= 1 << 8 * (substr $_,1) - 105 + ord $_ foreach @treasures;
walk( 0, 7, 0, q() ); ## Walk the tree starting from top-left
-say length $best_rt, q( - ), show_rt( $best_rt ); ## Show best route
+say '';
+say "Treasures: @treasures";
+say '#Steps: ',-1 + length $best_rt;
+say 'Route: ',show_rt( $best_rt ); ## Show best route
+say '';
sub walk {
my( $x, $y, $seen, $rt ) = @_;
@@ -44,18 +48,17 @@ sub walk {
|| $seen & ( my $v = 1 << ( my $t = 8*$y + $x ) );
$seen |= $v;
$rt .= chr $t;
- return ($best_rt,$best_len) = ($rt,-1+length $rt)
- if ($seen & $sol) == $sol;
+ return ($best_rt,$best_len) = ($rt,-1+length $rt) if ($seen & $sol) == $sol;
return if $best_len <= length $rt;
walk( $x + $_->[0], $y + $_->[1], $seen, $rt ) foreach @dir;
}
sub show_rt {
my %t = map { $_ => 1 } @treasures;
- return join q(),
- map { sprintf ' %s%s', exists$t{$_}?q(*):q( ), $_ }
- map { chr( ($_&7) + 97 ).(1 + ($_>>3)) }
- map { ord $_ }
- split m{}, shift;
+ return join q( ),
+ map { $_.( exists $t{$_} ? q(*) : q( ) ) }
+ map { chr( 97 + ($_&7) ).( 1 + ($_>>3) ) }
+ map { ord $_ }
+ split m{}, shift;
}