Home primes: Difference between revisions

3,313 bytes added ,  3 years ago
→‎{{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))
(→‎{{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;
for (flat 2..20, 65).map: -> $m {
@steps.push: @factors.join.Int while (@factors = prime-factors @steps[*-1]) > 1;
my ($stepnow, = +@steps, @factors) = now, $m;
 
say +@steps > 1
@steps.push: @factors.join.Int('_') while (@factors = prime-factors @steps[*-1].Int) > 1;
?? (@steps[0..*-2].map( { "HP$_\({--$step})" } ).join: ' = ')
 
!! ("HP$m"), " = ", @steps[*-1];
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 ($now, @steps, @factors) = $mnow, 49;
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) = HP22HP2_2(1) = 2112_11 (0.001 seconds)
HP5 = 5 (0.000 seconds)
HP6(1) = 232_3 (0.000 seconds)
HP7 = 7 (0.000 seconds)
HP8(13) = HP222HP2_2_2(12) = HP2337HP2_3_37(11) = HP31941HP3_19_41(10) = HP33371313HP3_3_3_7_13_13(9) = HP311123771HP3_11123771(8) = HP7149317941HP7_149_317_941(7) = HP22931219729HP229_31219729(6) = HP112084656339HP11_2084656339(5) = HP3347911118189HP3_347_911_118189(4) = HP11613496501723HP11_613_496501723(3) = HP97130517917327HP97_130517_917327(2) = HP531832651281459HP53_1832651281459(1) = 33311139653386351073_3_3_11_139_653_3863_5107 (0.014 seconds)
HP9(2) = HP33HP3_3(1) = 3113_11 (0.000 seconds)
HP10(4) = HP25HP2_5(3) = HP55HP5_5(2) = HP511HP5_11(1) = 7737_73 (0.001 seconds)
HP11 = 11 (0.000 seconds)
HP12(1) = 2232_2_3 (0.000 seconds)
HP13 = 13 (0.000 seconds)
HP14(5) = HP27HP2_7(4) = HP333HP3_3_3(3) = HP3337HP3_3_37(2) = HP4771HP47_71(1) = 1336713_367 (0.001 seconds)
HP15(4) = HP35HP3_5(3) = HP57HP5_7(2) = HP319HP3_19(1) = 112911_29 (0.001 seconds)
HP16(4) = HP2222HP2_2_2_2(3) = HP211101HP2_11_101(2) = HP3116397HP3_11_6397(1) = 316363733_163_6373 (0.001 seconds)
HP17 = 17 (0.000 seconds)
HP18(1) = 2332_3_3 (0.000 seconds)
HP19 = 19 (0.000 seconds)
HP20(15) = HP225HP2_2_5(14) = HP3355HP3_3_5_5(13) = HP51161HP5_11_61(12) = HP114651HP11_4651(11) = HP3312739HP3_3_12739(10) = HP17194867HP17_194867(9) = HP194122073HP19_41_22073(8) = HP709273797HP709_273797(7) = HP39713717791HP3_97_137_17791(6) = HP113610337981HP11_3610337981(5) = HP733914786213HP7_3391_4786213(4) = HP3333723311815403HP3_3_3_3_7_23_31_1815403(3) = HP131723655857429041HP13_17_23_655857429041(2) = HP772688237874641409HP7_7_2688237874641409(1) = 33183084756760714133_31_8308475676071413 (0.029 seconds)
HP65(19) = HP513HP5_13(18) = HP33319HP3_3_3_19(17) = HP1113233HP11_13_233(16) = HP11101203HP11_101203(15) = HP332353629HP3_3_23_53629(14) = HP33152324247HP3_3_1523_24247(13) = HP3337473732109HP3_3_3_7_47_3732109(12) = HP111801316843763HP11_18013_16843763(11) = HP151740406071813HP151_740406071813(10) = HP31313548335458223HP3_13_13_54833_5458223(9) = HP3397179373752371411HP3_3_97_179_373_7523_71411(8) = HP157116011350675311441HP1571_1601_1350675311441(7) = HP331333391143947279384649HP3_3_13_33391_143947_279384649(6) = HP11232040692636417517893491HP11_23_204069263_6417517893491(5) = HP711175663983039633268945697HP7_11_1756639_83039633268945697(4) = HP292951656531350398312122544283HP29_29_5165653_13503983_12122544283(3) = HP2283450603791282934064985326977HP228345060379_1282934064985326977(2) = HP333297925330304453879367290955541HP3_3_3_2979253_3030445387_9367290955541(1) = 1381321118321175157763339900357651</pre>1381_3211183211_75157763339900357651 (6.593 seconds)
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}}==
10,333

edits