aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--challenge-118/cheok-yin-fung/blog.txt2
-rw-r--r--challenge-118/cheok-yin-fung/perl/ch-2.pl8
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->$#*;
}