Magnanimous numbers: Difference between revisions
Content added Content deleted
(Realize in F#) |
|||
Line 328: | Line 328: | ||
486685 488489 515116 533176 551558 559952 595592 595598 600881 602081 |
486685 488489 515116 533176 551558 559952 595592 595598 600881 602081 |
||
</pre> |
</pre> |
||
=={{header|Julia}}== |
|||
<lang julia>using Primes |
|||
function ismagnanimous(n) |
|||
n < 10 && return true |
|||
for i in 1:ndigits(n)-1 |
|||
q, r = divrem(n, 10^i) |
|||
!isprime(q + r) && return false |
|||
end |
|||
return true |
|||
end |
|||
function magnanimous(N) |
|||
mvec, i = Int[], 0 |
|||
while length(mvec) < N |
|||
if ismagnanimous(i) |
|||
push!(mvec, i) |
|||
end |
|||
i += 1 |
|||
end |
|||
return mvec |
|||
end |
|||
const mag400 = magnanimous(400) |
|||
println("First 45 magnanimous numbers:\n", mag400[1:24], "\n", mag400[25:45]) |
|||
println("\n241st through 250th magnanimous numbers:\n", mag400[241:250]) |
|||
println("\n391st through 400th magnanimous numbers:\n", mag400[391:400]) |
|||
</lang>{{out}} |
|||
<pre> |
|||
First 45 magnanimous numbers: |
|||
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 11, 12, 14, 16, 20, 21, 23, 25, 29, 30, 32, 34, 38, 41] |
|||
[43, 47, 49, 50, 52, 56, 58, 61, 65, 67, 70, 74, 76, 83, 85, 89, 92, 94, 98, 101, 110] |
|||
241st through 250th magnanimous numbers: |
|||
[17992, 19972, 20209, 20261, 20861, 22061, 22201, 22801, 22885, 24407] |
|||
391st through 400th magnanimous numbers: |
|||
[486685, 488489, 515116, 533176, 551558, 559952, 595592, 595598, 600881, 602081] |
|||
</pre> |
|||
=={{header|Raku}}== |
=={{header|Raku}}== |