From 657910d89286dd5eefdf995a93612b1077bd6b9e Mon Sep 17 00:00:00 2001 From: James Smith Date: Wed, 15 Jun 2022 07:45:09 +0100 Subject: Update README.md --- challenge-169/james-smith/README.md | 13 +++++-------- 1 file 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; } ``` -- cgit