Magnanimous numbers: Difference between revisions
Content added Content deleted
m (→{{header|Factor}}: minor style tweak) |
|||
Line 358: | Line 358: | ||
</pre> |
</pre> |
||
=={{header|Phix}}== |
|||
<lang Phix>function magnanimous(integer n) |
|||
integer p = 1, r = 0 |
|||
while n>=10 do |
|||
r += remainder(n,10)*p |
|||
n = floor(n/10) |
|||
if not is_prime(n+r) then return false end if |
|||
p *= 10 |
|||
end while |
|||
return true |
|||
end function |
|||
sequence mag = {} |
|||
integer n = 0 |
|||
while length(mag)<400 do |
|||
if magnanimous(n) then mag &= n end if |
|||
n += 1 |
|||
end while |
|||
puts(1,"First 45 magnanimous numbers: ") pp(mag[1..45],{pp_Indent,30,pp_IntCh,false,pp_Maxlen,100}) |
|||
printf(1,"magnanimous numbers[241..250]: %v\n", {mag[241..250]}) |
|||
printf(1,"magnanimous numbers[391..400]: %v\n", {mag[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} |
|||
magnanimous numbers[241..250]: {17992,19972,20209,20261,20861,22061,22201,22801,22885,24407} |
|||
magnanimous numbers[391..400]: {486685,488489,515116,533176,551558,559952,595592,595598,600881,602081} |
|||
</pre> |
|||
=={{header|Raku}}== |
=={{header|Raku}}== |