I'm a software engineer, get me out of here: Difference between revisions
I'm a software engineer, get me out of here (view source)
Revision as of 04:08, 23 January 2021
, 3 years ago→{{header|Perl}}: a little less terse
SqrtNegInf (talk | contribs) m (→{{header|Perl}}: eliminate hard-coded value) |
SqrtNegInf (talk | contribs) m (→{{header|Perl}}: a little less terse) |
||
Line 792:
$w++;
sub
sub
my @directions = ( 1, -1, -$w-1 .. -$w+1, $w-1 .. $w+1 );
my $startpos =
my @nodes;
push @nodes, $-[0] while $d =~ /\d/g;
my %dist = map { $_ =>
my @best;
Line 808:
my $n = $best[$short] =~ tr/\n//;
print "shortest escape routes ($n) of length $short:\n",
$best[$short] =~ s/\d+/
print "\nshortest from (21,11) to (1,11):\n\t",
$dist{
print "\nshortest from (1,11) to (21,11):\n\t",
$dist{
@best = ();
$best[tr/ //] .= "\t$_\n" for map { values %$_ } values %dist;
print "\nlongestshortest paths (length $#best) :\n",
$best[-1] =~ s/\d+/
my @notreach = grep !$dist{$startpos}{$_}, @nodes;
print "\nnot reached from HQ:\n\t@notreach\n" =~ s/\d+/
@best = ();
$best[tr/ //] .= "\t$_\n" for values %{ $dist{$startpos} };
print "\nlongest reinforcement from HQ is $#best for:\n",
$best[-1] =~ s/\d+/
sub all_destinations
{
my @queue = shift;
|