aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCY Fung <fungcheokyin@gmail.com>2022-06-19 12:33:35 +0800
committerCY Fung <fungcheokyin@gmail.com>2022-06-19 12:33:35 +0800
commit98fb7f4abbac258af5af6b17001f045458de8692 (patch)
treebb4b37cb65573bb7169009dc6951aaa531c10636
parent9a4c469e476880da27c844a2037de73e93d38361 (diff)
downloadperlweeklychallenge-club-98fb7f4abbac258af5af6b17001f045458de8692.tar.gz
perlweeklychallenge-club-98fb7f4abbac258af5af6b17001f045458de8692.tar.bz2
perlweeklychallenge-club-98fb7f4abbac258af5af6b17001f045458de8692.zip
improve Task 1
-rw-r--r--challenge-169/cheok-yin-fung/perl/ch-1.pl11
1 files changed, 7 insertions, 4 deletions
diff --git a/challenge-169/cheok-yin-fung/perl/ch-1.pl b/challenge-169/cheok-yin-fung/perl/ch-1.pl
index 5a82cb55f9..35ffb2573f 100644
--- a/challenge-169/cheok-yin-fung/perl/ch-1.pl
+++ b/challenge-169/cheok-yin-fung/perl/ch-1.pl
@@ -2,7 +2,7 @@
# The Weekly Challenge 169
# Task 1 Brilliant Numbers Version 3.0
# See https://e7-87-83.github.io/coding/challenge_169.html
-# for a simpler version, up to first 241 brilliant numbers
+# for a simpler version, up to first 241 brilliant numbers
=pod DATA
number of 1-digit primes = 4
@@ -64,8 +64,10 @@ sub bn {
my @temp;
for my $i (0..$c) {
- for my $j ($i..scalar $prime{$digit_len}->@* - 1) {
- my $product = $prime{$digit_len}[$i]*$prime{$digit_len}[$j];
+ my $I = $prime{$digit_len}[$i];
+ my $_j = scalar $prime{$digit_len}->@* - 1;
+ for my $J ($prime{$digit_len}->@[$i..$_j]) {
+ my $product = $I*$J;
push @temp, $product;
}
}
@@ -81,7 +83,7 @@ sub bn {
-use Test::More tests=> 13;
+use Test::More tests=> 14;
ok bn(60) == 841;
ok bn(80) == 1079;
ok bn(100) == 1369;
@@ -94,6 +96,7 @@ ok bn(10000) == 696191;
ok bn(10416) == 851927;
ok bn(10537) == 994009;
ok bn(10538) == 1009*1009;
+ok bn(573927) == 9967*9973;
ok bn(573928) == 9973*9973;
# ref: OEIS:A078972