aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMohammad S Anwar <Mohammad.Anwar@yahoo.com>2022-04-12 14:15:21 +0100
committerGitHub <noreply@github.com>2022-04-12 14:15:21 +0100
commit5a663d99cb988a25b0448c9a26f422e33bbaa990 (patch)
tree966416b4b4a58bfac0b2429b96c68cfe66a2c124
parent6991062d881e39a1854cadcfa79dc03cd958b3d3 (diff)
parente3363927ff5511540969892106152f57cc24ea75 (diff)
downloadperlweeklychallenge-club-5a663d99cb988a25b0448c9a26f422e33bbaa990.tar.gz
perlweeklychallenge-club-5a663d99cb988a25b0448c9a26f422e33bbaa990.tar.bz2
perlweeklychallenge-club-5a663d99cb988a25b0448c9a26f422e33bbaa990.zip
Merge pull request #5927 from pokgopun/pwc156
remove unnecesary prime cache
-rw-r--r--challenge-156/pokgopun/perl/ch-1.pl12
1 files changed, 1 insertions, 11 deletions
diff --git a/challenge-156/pokgopun/perl/ch-1.pl b/challenge-156/pokgopun/perl/ch-1.pl
index d4b4ce1e2d..7aec2aadb0 100644
--- a/challenge-156/pokgopun/perl/ch-1.pl
+++ b/challenge-156/pokgopun/perl/ch-1.pl
@@ -5,7 +5,6 @@ use Math::Prime::Util qw/is_prime/;
my $n = shift;
$n = 10 unless $n && $n =~ /^\d+$/;
my $i;
-my %is_prime;
my @pn;
{
my $j = ++$i;
@@ -15,16 +14,7 @@ my @pn;
$j = int($j / 2);
redo if $j;
}
- if (defined $is_prime{$sum})
- {
- push @pn, $i if $is_prime{$sum};
- } else {
- $is_prime{$sum} = 0;
- if (is_prime($sum)){
- $is_prime{$sum} = 1;
- push @pn, $i
- }
- }
+ push @pn, $i if is_prime($sum);
redo if @pn < $n;
}
printf "%s\n", join(", ",@pn);