Magnanimous numbers: Difference between revisions
Content added Content deleted
m (Rust - use std::iter::from_fn) |
No edit summary |
||
Line 1,018: | Line 1,018: | ||
────────────────────────────────────────────── 391 ──► 400 magnanimous numbers ─────────────────────────────────────────────── |
────────────────────────────────────────────── 391 ──► 400 magnanimous numbers ─────────────────────────────────────────────── |
||
486685 488489 515116 533176 551558 559952 595592 595598 600881 602081 |
486685 488489 515116 533176 551558 559952 595592 595598 600881 602081 |
||
</pre> |
|||
=={{header|Ring}}== |
|||
<lang ring> |
|||
load "stdlib.ring" |
|||
n = -1 |
|||
sum = 0 |
|||
magn = [] |
|||
while sum < 45 |
|||
n = n + 1 |
|||
if n < 10 |
|||
add(magn,n) |
|||
sum = sum + 1 |
|||
else |
|||
nStr = string(n) |
|||
check = 0 |
|||
for m = 1 to len(nStr)-1 |
|||
nr1 = number(left(nStr,m)) |
|||
nr2 = number(right(nStr,len(nStr)-m)) |
|||
nr3 = nr1 + nr2 |
|||
if not isprime(nr3) |
|||
check = 1 |
|||
ok |
|||
next |
|||
if check = 0 |
|||
add(magn,n) |
|||
sum = sum + 1 |
|||
ok |
|||
ok |
|||
end |
|||
see "Magnanimous numbers 1-45:" + nl |
|||
showArray(magn) |
|||
n = -1 |
|||
sum = 0 |
|||
magn = [] |
|||
while sum < 250 |
|||
n = n + 1 |
|||
if n < 10 |
|||
sum = sum + 1 |
|||
else |
|||
nStr = string(n) |
|||
check = 0 |
|||
for m = 1 to len(nStr)-1 |
|||
nr1 = number(left(nStr,m)) |
|||
nr2 = number(right(nStr,len(nStr)-m)) |
|||
nr3 = nr1 + nr2 |
|||
if not isprime(nr3) |
|||
check = 1 |
|||
ok |
|||
next |
|||
if check = 0 |
|||
sum = sum + 1 |
|||
ok |
|||
if check = 0 and sum > 240 and sum < 251 |
|||
add(magn,n) |
|||
ok |
|||
ok |
|||
end |
|||
see nl |
|||
see "Magnanimous numbers 241-250:" + nl |
|||
showArray(magn) |
|||
func showArray array |
|||
txt = "" |
|||
see "[" |
|||
for n = 1 to len(array) |
|||
txt = txt + array[n] + "," |
|||
next |
|||
txt = left(txt,len(txt)-1) |
|||
txt = txt + "]" |
|||
see txt |
|||
</lang> |
|||
<pre> |
|||
Magnanimous numbers 1-45: |
|||
[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] |
|||
Magnanimous numbers 241-250: |
|||
[17992,19972,20209,20261,20861,22061,22201,22801,22885,24407] |
|||
</pre> |
</pre> |
||