diff options
| -rw-r--r-- | challenge-160/cheok-yin-fung/perl/ch-2.pl | 23 |
1 files changed, 5 insertions, 18 deletions
diff --git a/challenge-160/cheok-yin-fung/perl/ch-2.pl b/challenge-160/cheok-yin-fung/perl/ch-2.pl index 8c03ee08a5..d6e71a769a 100644 --- a/challenge-160/cheok-yin-fung/perl/ch-2.pl +++ b/challenge-160/cheok-yin-fung/perl/ch-2.pl @@ -49,31 +49,19 @@ sub ei { $new_ind = $ind-1; } elsif ($hint_lower+$cur_val == $hint_upper) { - $new_ind = $ind+$step; + $new_ind = $ind+$step; # follow the previous direction } elsif ($hint_lower == $hint_upper+$cur_val) { - $new_ind = $ind+$step; + $new_ind = $ind+$step; # follow the previous direction } else { if ($hint_lower+$cur_val > $hint_upper) { - if ($hint_lower+$cur_val >= $hint_upper-$n[$ind+1]) { - $new_ind = $ind+1; - } - else { - $new_ind = $ind-1; - } + $new_ind = $ind+1; } if ($hint_lower < $hint_upper+$cur_val) { $new_ind = $ind-1; } - - if ($hint_lower == $hint_upper+$cur_val - or - $hint_lower+$cur_val == $hint_upper) - { - $new_ind = $ind+$step; # follow the previous direction - } } # Prepare for the next loop block, or, stop @@ -88,10 +76,10 @@ sub ei { -use Test::More tests=>50; +use Test::More tests=>500; say "TESTING:"; my @n_temp; -for my $case (1..50) { +for my $case (1..500) { $n_temp[$_] = 1 + int rand(40) for (0..31); ok ei_simple(@n_temp) == ei(@n_temp); } @@ -106,4 +94,3 @@ sub ei_simple { } return -1; } - |
