Ruth-Aaron numbers: Difference between revisions
Content added Content deleted
(→{{header|Wren}}: Added code to find first triple based on prime divisors.) |
|||
Line 165: | Line 165: | ||
{{libheader|Wren-seq}} |
{{libheader|Wren-seq}} |
||
{{libheader|Wren-fmt}} |
{{libheader|Wren-fmt}} |
||
To find the first thirty Ruth-Aaron pairs and the first triple based on factors takes around 2.2 seconds. |
|||
However, with nearly 90 million trios of numbers to slog through, it takes around 68 minutes to find the first triple based on divisors. |
|||
<lang ecmascript>import "./math" for Int, Nums |
<lang ecmascript>import "./math" for Int, Nums |
||
import "./seq" for Lst |
import "./seq" for Lst |
||
Line 183: | Line 185: | ||
var countD = 0 |
var countD = 0 |
||
var countT = 0 |
var countT = 0 |
||
while ( |
while (countT < 1 || countD < 30 || countF < 30) { |
||
factors1 = factors2 |
factors1 = factors2 |
||
factors2 = factors3 |
factors2 = factors3 |
||
Line 194: | Line 196: | ||
countF = countF + 1 |
countF = countF + 1 |
||
} |
} |
||
if ( |
if (sum1 == sum2 && sum2 == sum3) { |
||
resT.add(n) |
resT.add(n) |
||
countT = countT + 1 |
countT = countT + 1 |
||
Line 216: | Line 218: | ||
System.print(resD.join(" ")) |
System.print(resD.join(" ")) |
||
System.print("\nFirst Ruth-Aaron triple (factors):") |
System.print("\nFirst Ruth-Aaron triple (factors):") |
||
System.print(resT[0]) |
|||
resT = [] // divisors only |
|||
n = 2 |
|||
factors1 = [] |
|||
factors2 = [2] |
|||
factors3 = [3] |
|||
sum1 = 0 |
|||
sum2 = 2 |
|||
sum3 = 3 |
|||
countT = 0 |
|||
while (countT < 1) { |
|||
factors1 = factors2 |
|||
factors2 = factors3 |
|||
factors3 = Int.primeFactors(n+2) |
|||
Lst.prune(factors3) |
|||
sum1 = sum2 |
|||
sum2 = sum3 |
|||
sum3 = Nums.sum(factors3) |
|||
if (sum1 == sum2 && sum2 == sum3) { |
|||
resT.add(n) |
|||
countT = countT + 1 |
|||
} |
|||
n = n + 1 |
|||
} |
|||
System.print("\nFirst Ruth-Aaron triple (divisors):") |
|||
System.print(resT[0])</lang> |
System.print(resT[0])</lang> |
||
Line 228: | Line 257: | ||
First Ruth-Aaron triple (factors): |
First Ruth-Aaron triple (factors): |
||
417162 |
417162 |
||
First Ruth-Aaron triple (divisors): |
|||
89460294 |
|||
</pre> |
</pre> |