aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJames Smith <js5@sanger.ac.uk>2022-03-29 15:55:41 +0100
committerGitHub <noreply@github.com>2022-03-29 15:55:41 +0100
commitbb78b5f790c1e6dc1d3ef8fcf45d26c0ab4ddfdd (patch)
treee0353ee176d75d62c358dc69fbd5829ce0972c0b
parent3bfd401364eb88675dfe45726aa5e776ef562b42 (diff)
downloadperlweeklychallenge-club-bb78b5f790c1e6dc1d3ef8fcf45d26c0ab4ddfdd.tar.gz
perlweeklychallenge-club-bb78b5f790c1e6dc1d3ef8fcf45d26c0ab4ddfdd.tar.bz2
perlweeklychallenge-club-bb78b5f790c1e6dc1d3ef8fcf45d26c0ab4ddfdd.zip
Update README.md
-rw-r--r--challenge-158/james-smith/README.md22
1 files changed, 21 insertions, 1 deletions
diff --git a/challenge-158/james-smith/README.md b/challenge-158/james-smith/README.md
index e11f4ed587..342202ccbf 100644
--- a/challenge-158/james-smith/README.md
+++ b/challenge-158/james-smith/README.md
@@ -51,7 +51,8 @@ sub additive_primes {
## Extra code
-Rewritten with single line for ...
+Rewritten with single line `for` ... (the original version of the code)
+
```perl
sub additive_primes_div {
my @res;
@@ -74,6 +75,25 @@ sub additive_primes_split {
@res;
}
```
+
+And an alternate using `sum0`...
+
+```perl
+sub additive_primes_split_sum0 {
+ my @res;
+ for( my $p = 2; $p <= $N ; $p = next_prime $p ) {
+ push @res, $p if is_prime sum0 split //, $p;
+ }
+ @res;
+}
+```
+
+### Relative performance
+
+ * `div`/`mod` method - 100%
+ * `split` - 75%
+ * `sum0 split` - 45%
+
# Challenge 2 - First series buban primes
***Write a script to compute first series cuban primes <= 1000. (First series cuban primes have the form `((x+1)^3-x^3)/(x+1-x)` = `3x^2+3x+1`)***