Home primes: Difference between revisions
m
syntax highlighting fixup automation
Thundergnat (talk | contribs) m (syntax highlighting fixup automation) |
|||
Line 47:
=={{header|Factor}}==
{{works with|Factor|0.99 2021-02-05}}
<
math.primes.factors math.ranges present prettyprint sequences
sequences.extras ;
Line 67:
: chain. ( n -- ) dup prime? [ prime. ] [ multi. ] if ;
2 20 [a,b] [ chain. ] each</
{{out}}
<pre>
Line 94:
{{trans|Wren}}
{{libheader|Go-rcu}}
<
import (
Line 239:
}
}
}</
{{out}}
Line 266:
=={{header|J}}==
<
hseq =: [,$:@step`(0&$)@.(1&p:)
fmtHP =: (' is prime',~":@])`('HP',":@],'(',":@[,')'&[)@.(*@[)
Line 272:
printHP =: 0 0&$@stdout@(fmtlist@hseq,(10{a.)&[)
printHP"0 [ 2}.i.21
exit 0</
{{out}}
<pre>2 is prime
Line 295:
=={{header|Julia}}==
<
function homeprimechain(n::BigInt)
Line 316:
printHPiter(i)
end
</
<pre>
Home Prime chain for 2: 2 is prime.
Line 374:
=={{header|Mathematica}}/{{header|Wolfram Language}}==
<
HP[n_] := FromDigits[Catenate[IntegerDigits /@ Sort[Catenate[ConstantArray @@@ FactorInteger[n]]]]]
HPChain[n_] := NestWhileList[HP, n, PrimeQ/*Not]
Row[Prepend["Home prime chain for " <> ToString[#] <> ": "]@Riffle[HPChain[#], ", "]] & /@ Range[2, 20] // Column
Row[Prepend["Home prime chain for 65: "]@Riffle[HPChain[65], ", "]]</
{{out}}
<pre>Home prime chain for 2: 2
Line 406:
{{libheader|bignum}}
This algorithm is really efficient. We get the result for HP2 to HP20 in about 6 ms and adding HP65 in 1.3 s. I think that the threshold to switch to Pollard-Rho is very important.
<
import bignum
Line 498:
break
else:
inc n</
{{out}}
Line 524:
=={{header|Perl}}==
{{libheader|ntheory}}
<
use warnings;
use ntheory 'factor';
Line 535:
else { print "HP$m = " }
print "$steps[-1]\n";
}</
{{out}}
Line 561:
=={{header|Phix}}==
Added a new mpz_pollard_rho routine, based on the [[wp:Pollard%27s_rho_algorithm]] C code.
<!--<
<span style="color: #008080;">with</span> <span style="color: #008080;">javascript_semantics</span>
<span style="color: #7060A8;">requires</span><span style="color: #0000FF;">(</span><span style="color: #008000;">"1.0.0"</span><span style="color: #0000FF;">)</span>
Line 597:
<span style="color: #008080;">end</span> <span style="color: #008080;">procedure</span>
<span style="color: #7060A8;">papply</span><span style="color: #0000FF;">(</span><span style="color: #7060A8;">tagset</span><span style="color: #0000FF;">(</span><span style="color: #000000;">20</span><span style="color: #0000FF;">,</span><span style="color: #000000;">2</span><span style="color: #0000FF;">)&</span><span style="color: #000000;">65</span><span style="color: #0000FF;">,</span><span style="color: #000000;">test</span><span style="color: #0000FF;">)</span>
<!--</
{{out}}
Using underscores to show the individual factors that were concatenated together
Line 690:
Using [https://modules.raku.org/search/?q=Prime+Factor Prime::Factor] from the [https://modules.raku.org/ Raku ecosystem].
<syntaxhighlight lang="raku"
my $start = now;
Line 713:
$now = now;
last if $step > 30;
}</
{{out}}
<pre>HP2 = 2 (0.000 seconds)
Line 771:
=={{header|REXX}}==
<
numeric digits 20 /*ensure handling of larger integers. */
parse arg LO HI . /*obtain optional arguments from the CL*/
Line 816:
/* [↓] The $ list has a leading blank.*/
if x==1 then return $ /*Is residual=unity? Then don't append.*/
return $ x /*return $ with appended residual. */</
{{out|output|text= when using the default input:}}
<pre>
Line 841:
=={{header|Sidef}}==
<
var steps = []
Line 853:
say ("HP(#{orig}) = ", steps.map { .join('_') }.join(' -> '))
}</
{{out}}
<pre>
Line 886:
Reaches HP20 in about 0.52 seconds but HP65 took just under 40 minutes!
<
import "/big" for BigInt
Line 911:
}
}
}</
{{out}}
Line 941:
{{libheader|Wren-gmp}}
This reduces the overall time taken to 5.1 seconds. The factorization method used is essentially the same as the Wren-cli version so the vast improvement in performance is due solely to the use of GMP.
<
import "./gmp" for Mpz
Line 968:
}
}
}</
{{out}}
|