From 8b3d4098625fe8fc4c962796812993aedf893441 Mon Sep 17 00:00:00 2001 From: Stephen Lynn Date: Sun, 12 Jun 2022 16:17:37 +0800 Subject: modified ch-2.jl; tried homeprime(48,65,96) --- challenge-168/steve-g-lynn/julia/ch-2.jl | 43 +++++++++++++++++++++++++++++++- challenge-168/steve-g-lynn/perl/ch-2.pl | 8 ++++++ challenge-168/steve-g-lynn/raku/ch-2.p6 | 7 ++++++ 3 files changed, 57 insertions(+), 1 deletion(-) diff --git a/challenge-168/steve-g-lynn/julia/ch-2.jl b/challenge-168/steve-g-lynn/julia/ch-2.jl index 19d4c7d498..0828857250 100755 --- a/challenge-168/steve-g-lynn/julia/ch-2.jl +++ b/challenge-168/steve-g-lynn/julia/ch-2.jl @@ -1,15 +1,56 @@ #! /usr/bin/julia +#time (bash) output: with homeprime.([10,16,20,48,65,96]) +#real 0m41.340s +#user 0m41.149s +#sys 0m0.493s + +#-- without homeprime(96): +#real 0m4.744s +#user 0m4.745s +#sys 0m0.467s + +#-- without .homeprime.([96,65]) +#real 0m1.072s +#user 0m1.138s +#sys 0m0.419s + +#-- without .homeprime.([96,65,48]) +#real 0m1.002s +#user 0m1.095s +#sys 0m0.384s + + + using Primes function homeprime(n::Int64) + return homeprime(BigInt(n)) +end + +function homeprime(n::BigInt) ncopy=n while (!isprime(ncopy)) - ncopy=parse(Int64,join(factor(Vector,ncopy))) + ncopy=parse(BigInt,join(factor(Vector,ncopy))) end return ncopy end +println(homeprime(10)) +#773 + println(homeprime(16)) #31636373 +println(homeprime(20)) +#3318308475676071413 + +println(homeprime(48)) +#6161791591356884791277 + +println(homeprime(65)) +#1381321118321175157763339900357651 + +println(homeprime(96)) +#172929671097972226356946608292031596899264419 + diff --git a/challenge-168/steve-g-lynn/perl/ch-2.pl b/challenge-168/steve-g-lynn/perl/ch-2.pl index 379ffd9078..0548ac1ebc 100755 --- a/challenge-168/steve-g-lynn/perl/ch-2.pl +++ b/challenge-168/steve-g-lynn/perl/ch-2.pl @@ -5,6 +5,14 @@ #user 0m0.019s #sys 0m0.007s +# but this fast time degrades sharply with larger problems +# +# real is 0m45.199s if home_prime(48) also printed +# real is 5m5.662s if home_prime of 48 and 65 also printed +# real is 8m50.059s if home_prime of 48, 65 and 96 also printed +# +# probably some slowdown in factor(.) for factors of very large primes + use Math::Prime::Util qw(is_prime factor); print &home_prime(10),"\n"; diff --git a/challenge-168/steve-g-lynn/raku/ch-2.p6 b/challenge-168/steve-g-lynn/raku/ch-2.p6 index 869bc8b3b5..09cbc4412b 100755 --- a/challenge-168/steve-g-lynn/raku/ch-2.p6 +++ b/challenge-168/steve-g-lynn/raku/ch-2.p6 @@ -5,6 +5,13 @@ #user 0m0.382s #sys 0m0.054s +#time if homeprime(48), homeprime(65) and homeprime(96) are also printed: +#real 2m23.931s +#user 2m23.527s +#sys 0m0.071s +# +# ( real 11.512s with homeprime (10,16,20,48,65) +# real 0.922s with homeprime (10,16,20,48) ) use Prime::Factor; -- cgit