Home primes: Difference between revisions

Content added Content deleted
m (→‎{{header|Factor}}: tweak output)
m (→‎{{header|Raku}}: Add links, minor style twiddles)
Line 84: Line 84:


=={{header|Raku}}==
=={{header|Raku}}==

Using [https://modules.raku.org/search/?q=Prime+Factor Prime::Factor] from the [https://modules.raku.org/ Raku ecosystem].


<lang perl6>use Prime::Factor;
<lang perl6>use Prime::Factor;


for flat 2..20, 65 -> $m {
for flat 2..20, 65 -> $m {
my ($n, @steps, @factors) = $m;
my ($n, $step, @steps, @factors) = $m, 0;
@steps.push: $n = @factors.join.Int while (@factors = prime-factors($n)) > 1;
@steps.push: $n = @factors.join.Int while (@factors = prime-factors $n) > 1;
say "HP$m = ", (@steps.map( { "{(++$step).fmt("HP$_\(%d)")}" } ).join: ' = '),
my $s = 0;
say "HP$m = ", (@steps[0..*-1]).map( { "{(++$s).fmt("HP$_\(%d)")}" } ).join(' = '),
+@steps ?? " = {@steps.tail}" !! $m;
+@steps ?? " = {@steps.tail}" !! $m;
}</lang>
}</lang>