Magnanimous numbers: Difference between revisions

Add CLU
(Add CLU)
Line 551:
486685, 488489, 515116, 533176, 551558, 559952, 595592, 595598, 600881, 602081
</pre>
 
=={{header|CLU}}==
<syntaxhighlight lang="clu">prime = proc (n: int) returns (bool)
if n < 2 then return(false) end
if n//2 = 0 then return(n=2) end
if n//3 = 0 then return(n=3) end
d: int := 5
while d*d <= n do
if n//d = 0 then return(false) end
d := d+2
if n//d = 0 then return(false) end
d := d+4
end
return(true)
end prime
 
sum_parts = iter (l: int) yields (int)
r: int := 0
s: int := 0
while l >= 10 do
r := r + (l // 10) * 10 ** s
s := s + 1
l := l / 10
yield(l + r)
end
end sum_parts
 
magnanimous = proc (n: int) returns (bool)
for s: int in sum_parts(n) do
if ~prime(s) then return(false) end
end
return(true)
end magnanimous
 
start_up = proc ()
po: stream := stream$primary_output()
n: int := 0
i: int := 0
c: int := 0
 
while i <= 400 do
while ~magnanimous(n) do n := n+1 end
i := i+1
 
if i=1 then stream$putl(po, "1-45:") c := 0
elseif i=241 then stream$putl(po, "\n241-250:") c := 0
elseif i=391 then stream$putl(po, "391-400:") c := 0
end
 
if i <= 45 cor (i > 240 cand i <= 250) cor (i > 390 cand i <= 400) then
stream$putright(po, int$unparse(n), 7)
c := c+1
if c = 10 then stream$putl(po, "") c := 0 end
end
n := n+1
end
end start_up</syntaxhighlight>
{{out}}
<pre>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
241-250:
17992 19972 20209 20261 20861 22061 22201 22801 22885 24407
391-400:
486685 488489 515116 533176 551558 559952 595592 595598 600881 602081</pre>
 
=={{header|Delphi}}==
Line 653 ⟶ 721:
559952 595592 595598 600881 602081
</pre>
 
 
=={{header|F_Sharp|F#}}==
2,115

edits