Ruth-Aaron numbers: Difference between revisions

→‎{{header|Wren}}: Added code to find first triple based on prime divisors.
(→‎{{header|Wren}}: Added code to find first triple based on prime divisors.)
Line 165:
{{libheader|Wren-seq}}
{{libheader|Wren-fmt}}
HaveTo only looked forfind the first thirty Ruth-Aaron triple based on factors (around 2.2 seconds overall) as, judgingpairs by the Raku experience, looking forand the first triple based on divisorsfactors istakes goingaround to2.2 be very slow indeed using Wrenseconds.
 
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
import "./seq" for Lst
Line 183 ⟶ 185:
var countD = 0
var countT = 0
while (countFcountT < 301 || countD < 30 || countTcountF < 130) {
factors1 = factors2
factors2 = factors3
Line 194 ⟶ 196:
countF = countF + 1
}
if (countT < 1 && sum1 == sum2 && sum2 == sum3) {
resT.add(n)
countT = countT + 1
Line 216 ⟶ 218:
System.print(resD.join(" "))
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>
 
Line 228 ⟶ 257:
First Ruth-Aaron triple (factors):
417162
 
First Ruth-Aaron triple (divisors):
89460294
</pre>
9,476

edits