aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJames Smith <js5@sanger.ac.uk>2022-06-15 07:45:09 +0100
committerGitHub <noreply@github.com>2022-06-15 07:45:09 +0100
commit657910d89286dd5eefdf995a93612b1077bd6b9e (patch)
tree648945a6cdb4a683b8e1e3e4ff6871b36553418a
parentd24994b1b8ce7ab171910e3d7bccc4541b8d9875 (diff)
downloadperlweeklychallenge-club-657910d89286dd5eefdf995a93612b1077bd6b9e.tar.gz
perlweeklychallenge-club-657910d89286dd5eefdf995a93612b1077bd6b9e.tar.bz2
perlweeklychallenge-club-657910d89286dd5eefdf995a93612b1077bd6b9e.zip
Update README.md
-rw-r--r--challenge-169/james-smith/README.md13
1 files changed, 5 insertions, 8 deletions
diff --git a/challenge-169/james-smith/README.md b/challenge-169/james-smith/README.md
index 55a91d2d32..e51614d1ea 100644
--- a/challenge-169/james-smith/README.md
+++ b/challenge-169/james-smith/README.md
@@ -30,8 +30,7 @@ For flexibility we define the max count `$MAX` as the command-line argument if o
```perl
for( my( $n, $c, $MAX, @f ) = ( 0, 0, @ARGV ? $ARGV[0] : 1e2 ); $c<$MAX; $n++ ) {
- say sprintf '%7d: %10d = %5d x %d', ++$c, $n, @f
- if 2 == ( @f=factor($n) ) && length( $f[0] ) == length $f[1];
+ say sprintf '%7d: %10d = %5d x %d', ++$c, $n, @f if 2 == ( @f = factor $n ) && length $f[0] == length $f[1];
}
```
@@ -102,7 +101,7 @@ If we remove the pretty print this reduces to:
```perl
for( my( $n, $c, $MAX, @f ) = ( 0, 0, @ARGV ? $ARGV[0] : 1e2 ); $c<$MAX; $n++ ) {
- $c++, say $n if 2 == ( @f=factor($n) ) && length( $f[0] ) == length $f[1];
+ $c++, say $n if 2 == ( @f = factor $n ) && length $f[0] == length $f[1];
}
```
@@ -125,11 +124,9 @@ We then check to see if any of the factors does not have its square as a factor.
We then compute the `gcd` of these powers - if it is 1 then we display the result - our output is index, value and the prime factorisation, most of the loop is for the pretty print.
```perl
-for( my( $n, $c, $MAX ) = ( 2, 0, @ARGV ? $ARGV[0] : 1e2 ); $c<$MAX; $n++ ) {
- say sprintf '%6d: %15d = %s', ++$c, $n,
- join ' . ', map { "$_->[0]^$_->[1]" } @f
+for( my( $n, $c, $MAX, @f ) = ( 2, 0, @ARGV ? $ARGV[0] : 1e2 ); $c < $MAX; $n++ ) {
+ say sprintf '%6d: %15d = %s', ++$c, $n, join ' . ', map { "$_->[0]^$_->[1]" } @f
if 1 == gcd map { $_->[1] < 2 ? next : $_->[1] } @f = factor_exp $n;
-
}
```
@@ -191,7 +188,7 @@ The following are the first 50 achilles numbers.
If we remove the pretty print this reduces to:
```perl
-for( my( $n, $c, $MAX ) = ( 2, 0, @ARGV ? $ARGV[0] : 1e2 ); $c<$MAX; $n++ ) {
+for( my( $n, $c, $MAX, @f ) = ( 2, 0, @ARGV ? $ARGV[0] : 1e2 ); $c<$MAX; $n++ ) {
$c++, say $n if 1 == gcd map { $_->[1] < 2 ? next : $_->[1] } @f = factor_exp $n;
}
```