Sum of square and cube digits of an integer are primes: Difference between revisions
Content added Content deleted
Not a robot (talk | contribs) (Add COBOL) |
Not a robot (talk | contribs) (Add CLU) |
||
Line 54: | Line 54: | ||
{{out}} |
{{out}} |
||
<pre>⟨ 16 17 25 28 34 37 47 52 64 ⟩</pre> |
<pre>⟨ 16 17 25 28 34 37 47 52 64 ⟩</pre> |
||
=={{header|CLU}}== |
|||
<lang clu>digit_sum = proc (n: int) returns (int) |
|||
sum: int := 0 |
|||
while n>0 do |
|||
sum := sum + n // 10 |
|||
n := n / 10 |
|||
end |
|||
return(sum) |
|||
end digit_sum |
|||
% The numbers tested for primality are very small, |
|||
% so this simple test suffices. |
|||
prime = proc (n: int) returns (bool) |
|||
if n<2 then return(false) end |
|||
d: int := 2 |
|||
while d*d <= n do |
|||
if n//d=0 then return(false) end |
|||
d := d+1 |
|||
end |
|||
return(true) |
|||
end prime |
|||
accept = proc (n: int) returns (bool) |
|||
return(prime(digit_sum(n**2)) cand prime(digit_sum(n**3))) |
|||
end accept |
|||
start_up = proc () |
|||
po: stream := stream$primary_output() |
|||
for i: int in int$from_to(1, 99) do |
|||
if accept(i) then |
|||
stream$puts(po, int$unparse(i) || " ") |
|||
end |
|||
end |
|||
end start_up</lang> |
|||
{{out}} |
|||
<pre>16 17 25 28 34 37 47 52 64</pre> |
|||
=={{header|COBOL}}== |
=={{header|COBOL}}== |