diff options
| author | E7-87-83 <fungcheokyin@gmail.com> | 2021-06-27 07:33:51 +0800 |
|---|---|---|
| committer | E7-87-83 <fungcheokyin@gmail.com> | 2021-06-27 07:33:51 +0800 |
| commit | 66b4bb70eeceda884c896b35bb1c9f30a2cc2cf3 (patch) | |
| tree | 099082e0fb1dc07123ba454353db10c6c9816942 | |
| parent | 3af566d768a72ae55ad186a5b0a6523098d7f1ab (diff) | |
| download | perlweeklychallenge-club-66b4bb70eeceda884c896b35bb1c9f30a2cc2cf3.tar.gz perlweeklychallenge-club-66b4bb70eeceda884c896b35bb1c9f30a2cc2cf3.tar.bz2 perlweeklychallenge-club-66b4bb70eeceda884c896b35bb1c9f30a2cc2cf3.zip | |
improve &compare_mini
| -rw-r--r-- | challenge-118/cheok-yin-fung/blog.txt | 2 | ||||
| -rw-r--r-- | challenge-118/cheok-yin-fung/perl/ch-2.pl | 8 |
2 files changed, 4 insertions, 6 deletions
diff --git a/challenge-118/cheok-yin-fung/blog.txt b/challenge-118/cheok-yin-fung/blog.txt new file mode 100644 index 0000000000..46fca31c76 --- /dev/null +++ b/challenge-118/cheok-yin-fung/blog.txt @@ -0,0 +1,2 @@ +https://e7-87-83.github.io/coding/challenge_118.html +https://e7-87-83.github.io/coding/challenge_118t1.html diff --git a/challenge-118/cheok-yin-fung/perl/ch-2.pl b/challenge-118/cheok-yin-fung/perl/ch-2.pl index 1d43c630e9..d74f82c92e 100644 --- a/challenge-118/cheok-yin-fung/perl/ch-2.pl +++ b/challenge-118/cheok-yin-fung/perl/ch-2.pl @@ -6,23 +6,19 @@ # 3 2^ 1 2 # 2 1 4 3 # 3^ 2 3 2 - a b c d -------- N * * * |4 * * * * |3 * x * * |2 * x x * |1 - x : b1, b2, c1 - b1 <-> b2 : 3 b1 <-> c1 : 3 b2 <-> c1 : 2 a4(N) <-> b1 : 2 a4 <-> b2 : 1 a4 <-> c1 : 3 - N -> b1 -> b2 -> c1 : 2 + 3 + 2 = 7 N -> b1 -> c1 -> b2 : 2 + 3 + 2 = 7 N -> b2 -> b1 -> c1 : 1 + 3 + 3 = 7 @@ -65,11 +61,11 @@ my $iter = permutations( \@treasures ); while (my $p = $iter->next) { my $path_length = dist_fun([0,0], $p->[0]); my $i = 0; - while ($i < $p->$#*) { + while ($i < $p->$#* && $path_length < $min_path_length) { $path_length += dist_fun($p->[$i], $p->[$i+1]); $i++; } - compare_mini($path_length, $p); + compare_mini($path_length, $p) if $i == $p->$#*; } |
