Home primes: Difference between revisions
→{{header|Raku}}: Plagiarize underscore separator idea from Phix, add some basic timing info., do partial HP49
m (Use home not Home (as per wp and elsewhere)) |
Thundergnat (talk | contribs) (→{{header|Raku}}: Plagiarize underscore separator idea from Phix, add some basic timing info., do partial HP49) |
||
Line 293:
=={{header|Raku}}==
Not the fastest, but not too bad either. Make an abortive attempt at HP49.
Assuming there are n steps; HP49(n - 26) is slow, HP49(n - 32) is ''really'' slow, and I gave up on HP49(n - 35) after 45 minutes.
Using [https://modules.raku.org/search/?q=Prime+Factor Prime::Factor] from the [https://modules.raku.org/ Raku ecosystem].
Line 298 ⟶ 302:
<lang perl6>use Prime::Factor;
my $start = now;
for flat 2..20, 65 -> $m {▼
my (@steps, @factors) = $m;▼
@steps.push: @factors.join.Int while (@factors = prime-factors @steps[*-1]) > 1;▼
my ($
?? (@steps[0..*-2].map( { "HP$_\({--$step})" } ).join: ' = ')▼
▲ say (my $step = +@steps) > 1 ?? (@steps[0..*-2].map( { "HP$_\({--$step})" } ).join: ' = ') !! ("HP$m"),
" = ", @steps[*-1], " ({(now - $now).fmt("%0.3f")} seconds)";
}
say "Total elapsed time: {(now - $start).fmt("%0.3f")} seconds\n";
say 'HP49:';
my $step = 0;
while (@factors = prime-factors @steps[*-1].Int) > 1 {
@steps.push: @factors.join('_');
say "HP{@steps[$step].Int}\(n - {++$step}) = ", @steps[*-1], " ({(now - $now).fmt("%0.3f")} seconds)";
$now = now;
last if $step == 30;
}</lang>
{{out}}
<pre>HP2 = 2 (0.000 seconds)
HP3 = 3 (0.000 seconds)
HP4(2) =
HP5 = 5 (0.000 seconds)
HP6(1) =
HP7 = 7 (0.000 seconds)
HP8(13) =
HP9(2) =
HP10(4) =
HP11 = 11 (0.000 seconds)
HP12(1) =
HP13 = 13 (0.000 seconds)
HP14(5) =
HP15(4) =
HP16(4) =
HP17 = 17 (0.000 seconds)
HP18(1) =
HP19 = 19 (0.000 seconds)
HP20(15) =
HP65(19) =
Total elapsed time: 6.651 seconds
HP49:
HP49(n - 1) = 7_7 (0.000 seconds)
HP77(n - 2) = 7_11 (0.000 seconds)
HP711(n - 3) = 3_3_79 (0.000 seconds)
HP3379(n - 4) = 31_109 (0.000 seconds)
HP31109(n - 5) = 13_2393 (0.000 seconds)
HP132393(n - 6) = 3_44131 (0.000 seconds)
HP344131(n - 7) = 17_31_653 (0.000 seconds)
HP1731653(n - 8) = 7_11_43_523 (0.000 seconds)
HP71143523(n - 9) = 11_11_577_1019 (0.000 seconds)
HP11115771019(n - 10) = 311_35742029 (0.000 seconds)
HP31135742029(n - 11) = 7_17_261644891 (0.000 seconds)
HP717261644891(n - 12) = 11_19_3431873899 (0.002 seconds)
HP11193431873899(n - 13) = 11_613_4799_345907 (0.001 seconds)
HP116134799345907(n - 14) = 3_204751_189066719 (0.001 seconds)
HP3204751189066719(n - 15) = 3_1068250396355573 (0.003 seconds)
HP31068250396355573(n - 16) = 621611_49980213343 (0.006 seconds)
HP62161149980213343(n - 17) = 3_3_6906794442245927 (0.005 seconds)
HP336906794442245927(n - 18) = 73_4615161567701999 (0.010 seconds)
HP734615161567701999(n - 19) = 3_13_18836286194043641 (0.009 seconds)
HP31318836286194043641(n - 20) = 3_3_3_43_14369_161461_11627309 (0.005 seconds)
HP333431436916146111627309(n - 21) = 3_32057_1618455677_2142207827 (0.187 seconds)
HP33205716184556772142207827(n - 22) = 3_1367_2221_5573_475297_1376323127 (0.008 seconds)
HP31367222155734752971376323127(n - 23) = 7_3391_51263_25777821480557336017 (0.005 seconds)
HP733915126325777821480557336017(n - 24) = 47_67_347_431_120361987_12947236602187 (0.054 seconds)
HP476734743112036198712947236602187(n - 25) = 3_7_7_17_12809_57470909_57713323_4490256751 (0.168 seconds)
HP377171280957470909577133234490256751(n - 26) = 3096049809383_121823389214993262890297 (30.753 seconds)
HP3096049809383121823389214993262890297(n - 27) = 7_379_62363251_18712936424989555929478399 (0.132 seconds)
HP73796236325118712936424989555929478399(n - 28) = 13_1181_145261411_33089538087518197265265053 (0.032 seconds)
HP13118114526141133089538087518197265265053(n - 29) = 3_19_521_441731977174163487542111577539726749 (0.002 seconds)
HP319521441731977174163487542111577539726749(n - 30) = 59_5415617656474189392601483764603009147911 (0.002 seconds)</pre>
=={{header|Wren}}==
|