Ruth-Aaron numbers: Difference between revisions
Content added Content deleted
Thundergnat (talk | contribs) m (→{{header|Raku}}: Add RA triple divisors.) |
(Added Wren) |
||
Line 118: | Line 118: | ||
First Ruth-Aaron triple (Divisors): |
First Ruth-Aaron triple (Divisors): |
||
89460294</pre> |
89460294</pre> |
||
=={{header|Wren}}== |
|||
{{libheader|Wren-math}} |
|||
{{libheader|Wren-seq}} |
|||
{{libheader|Wren-fmt}} |
|||
Have only looked for the first Ruth-Aaron triple based on factors (around 6 seconds overall) as, judging by the Raku experience, looking for the first triple based on divisors is going to be very slow indeed using Wren. |
|||
<lang ecmascript>import "./math" for Int, Nums |
|||
import "./seq" for Lst |
|||
import "./fmt" for Fmt |
|||
var resF = [] |
|||
var resD = [] |
|||
var resT = [] // factors only |
|||
var n = 1 |
|||
var countF = 0 |
|||
var countD = 0 |
|||
var countT = 0 |
|||
while (countF < 30 || countD < 30 || countT < 1) { |
|||
var factors1 = Int.primeFactors(n) |
|||
var factors2 = Int.primeFactors(n+1) |
|||
var factors3 = Int.primeFactors(n+2) |
|||
var sum1 = Nums.sum(factors1) |
|||
var sum2 = Nums.sum(factors2) |
|||
var sum3 = Nums.sum(factors3) |
|||
if (countF < 30 && sum1 == sum2) { |
|||
resF.add(n) |
|||
countF = countF + 1 |
|||
} |
|||
if (countT < 1 && sum1 == sum2 && sum2 == sum3) { |
|||
resT.add(n) |
|||
countT = countT + 1 |
|||
} |
|||
if (countD < 30) { |
|||
Lst.prune(factors1) |
|||
Lst.prune(factors2) |
|||
if (Nums.sum(factors1) == Nums.sum(factors2)) { |
|||
resD.add(n) |
|||
countD = countD + 1 |
|||
} |
|||
} |
|||
n = n + 1 |
|||
} |
|||
System.print("First 30 Ruth-Aaron numbers (factors):") |
|||
System.print(resF.join(" ")) |
|||
System.print("\nFirst 30 Ruth-Aaron numbers (divisors):") |
|||
System.print(resD.join(" ")) |
|||
System.print("\nFirst Ruth-Aaron triple (factors):") |
|||
System.print(resT[0])</lang> |
|||
{{out}} |
|||
<pre> |
|||
First 30 Ruth-Aaron numbers (factors): |
|||
5 8 15 77 125 714 948 1330 1520 1862 2491 3248 4185 4191 5405 5560 5959 6867 8280 8463 10647 12351 14587 16932 17080 18490 20450 24895 26642 26649 |
|||
First 30 Ruth-Aaron numbers (divisors): |
|||
5 24 49 77 104 153 369 492 714 1682 2107 2299 2600 2783 5405 6556 6811 8855 9800 12726 13775 18655 21183 24024 24432 24880 25839 26642 35456 40081 |
|||
First Ruth-Aaron triple (factors): |
|||
417162 |
|||
</pre> |