diff options
| author | Gustavo L. de M. Chaves <gustavo@cpqd.com.br> | 2019-05-08 22:34:00 -0300 |
|---|---|---|
| committer | Gustavo L. de M. Chaves <gustavo@cpqd.com.br> | 2019-05-08 22:34:00 -0300 |
| commit | 0c04fc8ce603860f5faceb1764f5b379b93697ce (patch) | |
| tree | 269c10c00df622f1714c4f065cbd982495581fd4 /challenge-007 | |
| parent | 3ac4799328b78382bd071404cb508535c1118b9d (diff) | |
| download | perlweeklychallenge-club-0c04fc8ce603860f5faceb1764f5b379b93697ce.tar.gz perlweeklychallenge-club-0c04fc8ce603860f5faceb1764f5b379b93697ce.tar.bz2 perlweeklychallenge-club-0c04fc8ce603860f5faceb1764f5b379b93697ce.zip | |
Optimize a hash into an array
Diffstat (limited to 'challenge-007')
| -rwxr-xr-x | challenge-007/gustavo-chaves/perl5/ch-2.pl | 6 |
1 files changed, 3 insertions, 3 deletions
diff --git a/challenge-007/gustavo-chaves/perl5/ch-2.pl b/challenge-007/gustavo-chaves/perl5/ch-2.pl index ddb900251f..5ced16a2d6 100755 --- a/challenge-007/gustavo-chaves/perl5/ch-2.pl +++ b/challenge-007/gustavo-chaves/perl5/ch-2.pl @@ -30,8 +30,8 @@ sub first_shortest_ladder { $distance += 1 if substr($word_i, $k, 1) ne substr($word_j, $k, 1); } if ($distance == 1) { - $graph{$word_i}{$word_j} = undef; - $graph{$word_j}{$word_i} = undef; + push @{$graph{$word_i}}, $word_j; + push @{$graph{$word_j}}, $word_i; } } $dist{$word_i} = @$wordlist + 1; # infinity @@ -47,7 +47,7 @@ sub first_shortest_ladder { last if $u eq $target; # found a shortest path to $target - foreach my $v (grep {exists $graph{$_}} keys %$neighbors) { + foreach my $v (grep {exists $graph{$_}} @$neighbors) { my $alt = $dist{$u} + 1; if ($alt < $dist{$v}) { $dist{$v} = $alt; |
