diff options
| author | Michael Manring <michael@manring> | 2022-04-12 16:05:05 +0700 |
|---|---|---|
| committer | Michael Manring <michael@manring> | 2022-04-12 16:05:05 +0700 |
| commit | e3363927ff5511540969892106152f57cc24ea75 (patch) | |
| tree | c03e3a09c7e8a0a5d44fb3c2214a7943f1025998 /challenge-156 | |
| parent | 635f81890b1d36fd472afbe94df2c7cb0a289d6e (diff) | |
| download | perlweeklychallenge-club-e3363927ff5511540969892106152f57cc24ea75.tar.gz perlweeklychallenge-club-e3363927ff5511540969892106152f57cc24ea75.tar.bz2 perlweeklychallenge-club-e3363927ff5511540969892106152f57cc24ea75.zip | |
remove unnecesary prime cache
Diffstat (limited to 'challenge-156')
| -rw-r--r-- | challenge-156/pokgopun/perl/ch-1.pl | 12 |
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); |
