diff options
| author | Gustavo L. de M. Chaves <gustavo@cpqd.com.br> | 2019-05-08 22:37:04 -0300 |
|---|---|---|
| committer | Gustavo L. de M. Chaves <gustavo@cpqd.com.br> | 2019-05-08 22:37:04 -0300 |
| commit | 0aae50e6dc686fad8e6d51097768f97cf60638f0 (patch) | |
| tree | 61840c8738cdc152b17b5c38b56f98a3f82da340 /challenge-007 | |
| parent | 0c04fc8ce603860f5faceb1764f5b379b93697ce (diff) | |
| download | perlweeklychallenge-club-0aae50e6dc686fad8e6d51097768f97cf60638f0.tar.gz perlweeklychallenge-club-0aae50e6dc686fad8e6d51097768f97cf60638f0.tar.bz2 perlweeklychallenge-club-0aae50e6dc686fad8e6d51097768f97cf60638f0.zip | |
Optimize the calculation of a constant
Diffstat (limited to 'challenge-007')
| -rwxr-xr-x | challenge-007/gustavo-chaves/perl5/ch-2.pl | 6 |
1 files changed, 4 insertions, 2 deletions
diff --git a/challenge-007/gustavo-chaves/perl5/ch-2.pl b/challenge-007/gustavo-chaves/perl5/ch-2.pl index 5ced16a2d6..e9d757481a 100755 --- a/challenge-007/gustavo-chaves/perl5/ch-2.pl +++ b/challenge-007/gustavo-chaves/perl5/ch-2.pl @@ -21,7 +21,9 @@ sub first_shortest_ladder { my (%graph, %dist, %prev); - my $length = length $source; + my $length = length $source; + my $infinity = @$wordlist + 1; + for my $i (0 .. @$wordlist-2) { my $word_i = $wordlist->[$i]; foreach my $word_j (@{$wordlist}[$i+1 .. @$wordlist-1]) { @@ -34,7 +36,7 @@ sub first_shortest_ladder { push @{$graph{$word_j}}, $word_i; } } - $dist{$word_i} = @$wordlist + 1; # infinity + $dist{$word_i} = $infinity; $prev{$word_i} = undef; } |
