Ruth-Aaron numbers: Difference between revisions
m
syntax highlighting fixup automation
No edit summary |
Thundergnat (talk | contribs) m (syntax highlighting fixup automation) |
||
Line 37:
This uses a large amount of memory - too much for Algol 68G under Windows (and possibly under Linux).<br>
With max number set to 1 000 000, Algol 68G can find the first triple using factors in a few seconds (the loop to find the first divisors triple must be commented out or removed) - Real time: 0.941 s on TIO.RUN for the cutdown version.
<
# of the prime factors or divisors are equal #
INT max number = 99 000 000; # max number we will consider #
Line 139:
print( ( newline, "First Ruth-Aaron triple (factors): ", whole( fra3, 0 ) ) );
print( ( newline, "First Ruth-Aaron triple (divisors): ", whole( dra3, 0 ) ) )
END</
{{out}}
<pre>
Line 157:
=={{header|C++}}==
This takes about 2 minutes 24 seconds (3.2GHz Quad-Core Intel Core i5).
<
#include <iostream>
Line 243:
dsum2 = dsum3;
}
}</
{{out}}
Line 264:
=={{header|Factor}}==
{{works with|Factor|0.99 2022-04-03}}
<
math.primes.factors prettyprint ranges sequences ;
Line 283:
"First 30 Ruth-Aaron numbers (divisors):" print
RA-d list.</
{{out}}
<pre>
Line 301:
{{libheader|Go-rcu}}
Takes about 4.5 minutes.
<
import (
Line 382:
fmt.Println("\nFirst Ruth-Aaron triple (divisors):")
fmt.Println(resT[0])
}</
{{out}}
Line 400:
=={{header|Haskell}}==
<
import Data.List.Split ( chunksOf )
Line 450:
putStrLn "First 30 Ruth-Aaron numbers( divisors ):"
mapM_ (\nlin -> putStrLn $ foldl1 ( ++ ) $ map (\st -> formatNumber (maxlen2 + 2) st )
nlin ) numberlines2</
{{out}}
<pre>First 30 Ruth-Aaaron numbers ( factors ) :
Line 470:
Thus:
<
30{.1 2+/~I. 2 =/\ +/@q: 1+i.100000
5 6
Line 534:
26642 26643
35456 35457
40081 40082</
=={{header|Julia}}==
<
using Primes
Line 563:
println("\nRuth Aaron triple starts at: ", findfirst(ruthaarontriple, 1:100000000))
println("\nRuth Aaron factor triple starts at: ", findfirst(ruthaaronfactorstriple, 1:10000000))
</
<pre>
30 Ruth Aaron numbers:
Line 583:
==={{header|Free Pascal}}===
all depends on fast prime decomposition.
<
// gets factors of consecutive integers fast
// limited to 1.2e11
Line 989:
writeln('First Ruth-Aaron triple (divisors):');
writeln(findfirstTripplesFactor(false):10);
end.</
{{out|@TIO.RUN}}
<pre>
Line 1,012:
=={{header|Perl}}==
<
use strict;
Line 1,037:
$n++;
}
print "divisors:\n\n@answers\n" =~ s/.{60}\K /\n/gr;</
{{out}}
<pre>
Line 1,056:
{{libheader|Phix/online}}
You can run this online [http://phix.x10.mx/p2js/ruthaaron.htm here].
<!--<
<span style="color: #008080;">with</span> <span style="color: #008080;">javascript_semantics</span>
<span style="color: #008080;">procedure</span> <span style="color: #000000;">ruth_aaron</span><span style="color: #0000FF;">(</span><span style="color: #004080;">bool</span> <span style="color: #000000;">d</span><span style="color: #0000FF;">,</span> <span style="color: #004080;">integer</span> <span style="color: #000000;">n</span><span style="color: #0000FF;">=</span><span style="color: #000000;">30</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">l</span><span style="color: #0000FF;">=</span><span style="color: #000000;">2</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">i</span><span style="color: #0000FF;">=</span><span style="color: #000000;">1</span><span style="color: #0000FF;">)</span>
Line 1,090:
<span style="color: #000000;">ruth_aaron</span><span style="color: #0000FF;">(</span><span style="color: #004600;">true</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">1</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">3</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">89460000</span><span style="color: #0000FF;">)</span> <span style="color: #000080;font-style:italic;">-- (0.1s)
--ruth_aaron(true, 1, 3) -- (24 minutes 30s)</span>
<!--</
{{out}}
<pre>
Line 1,110:
<code>primefactors</code> is defined at [[Prime decomposition#Quackery]].
<
witheach
[ tuck != if
Line 1,149:
raf echo
cr cr
rad echo</
{{out}}
Line 1,160:
=={{header|Raku}}==
<syntaxhighlight lang="raku"
my @pf = lazy (^∞).hyper(:1000batch).map: *.&prime-factors.sum;
Line 1,178:
# Really, really, _really_ slow. 186(!) minutes... but with no cheating or "leg up".
put "\nFirst Ruth-Aaron triple (Divisors):\n" ~
(1..∞).first: { @upf[$_] == @upf[$_ + 1] == @upf[$_ + 2] }</
{{out}}
<pre>First 30 Ruth-Aaron numbers (Factors):
Line 1,193:
=={{header|Sidef}}==
<
say 30.by {|n| (sopfr(n) == sopfr(n+1)) && (n > 0) }.join(' ')
say "\nFirst 30 Ruth-Aaron numbers (divisors):"
say 30.by {|n| ( sopf(n) == sopf(n+1)) && (n > 0) }.join(' ')</
{{out}}
Line 1,215:
However, with nearly 90 million trios of numbers to slog through, it takes around 68 minutes to find the first triple based on divisors.
<
import "./seq" for Lst
import "./fmt" for Fmt
Line 1,292:
System.print("\nFirst Ruth-Aaron triple (divisors):")
System.print(resT[0])</
{{out}}
Line 1,310:
=={{header|XPL0}}==
<
int N, AllDiv; \all divisors vs. only prime divisors
int F, F0, S, Q;
Line 1,345:
CrLf(0);
Ruth(false);
]</
{{out}}
|