Jump to content

Ruth-Aaron numbers: Difference between revisions

julia example
m (→‎{{header|Phix}}: added commented out full run line/time)
(julia example)
Line 33:
;*[[oeis:A039752|OEIS:A039752 - Ruth-Aaron numbers (2): sum of prime divisors of n = sum of prime divisors of n+1 (both taken with multiplicity)]]
 
=={{header|Julia}}==
<lang julia>using Lazy
using Primes
 
sumprimedivisors(n) = sum([p[1] for p in factor(n)])
ruthaaron(n) = sumprimedivisors(n) == sumprimedivisors(n + 1)
ruthaarontriple(n) = sumprimedivisors(n) == sumprimedivisors(n + 1) ==
sumprimedivisors(n + 2)
 
sumprimefactors(n) = sum([p[1] * p[2] for p in factor(n)])
ruthaaronfactors(n) = sumprimefactors(n) == sumprimefactors(n + 1)
ruthaaronfactorstriple(n) = sumprimefactors(n) == sumprimefactors(n + 1) ==
sumprimefactors(n + 2)
 
raseq = @>> Lazy.range() filter(ruthaaron)
rafseq = @>> Lazy.range() filter(ruthaaronfactors)
 
println("30 Ruth Aaron numbers:")
foreach(p -> print(lpad(p[2], 6), p[1] % 10 == 0 ? "\n" : ""),
enumerate(collect(take(30, raseq))))
 
println("\n30 Ruth Aaron factor numbers:")
foreach(p -> print(lpad(p[2], 6), p[1] % 10 == 0 ? "\n" : ""),
enumerate(collect(take(30, rafseq))))
 
println("\nRuth Aaron triple starts at: ", findfirst(x -> ruthaarontriple(x), 1:100000000))
println("\nRuth Aaron factor triple starts at: ", findfirst(ruthaaronfactorstriple, 1:10000000))
</lang>{{out}}
<pre>
30 Ruth Aaron numbers:
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
 
30 Ruth Aaron factor numbers:
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
 
Ruth Aaron triple starts at: 89460294
 
Ruth Aaron factor triple starts at: 417162
</pre>
 
 
4,108

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.