Pernicious numbers: Difference between revisions

Add CLU
(Add CLU)
Line 761:
<pre>(3 5 6 7 9 10 11 12 13 14 17 18 19 20 21 22 24 25 26 28 31 33 34 35 36)
(888888877 888888878 888888880 888888883 888888885 888888886)</pre>
 
=={{header|CLU}}==
<lang clu>% The population count of an integer is never going to be
% higher than the amount of bits in it (max 64)
% so we can get away with a very simple primality test.
is_prime = proc (n: int) returns (bool)
if n<=2 then return(n=2) end
if n//2=0 then return(false) end
for i: int in int$from_to_by(n+2, n/2, 2) do
if n//i=0 then return(false) end
end
return(true)
end is_prime
 
% Find the population count of a number
pop_count = proc (n: int) returns (int)
c: int := 0
while n > 0 do
c := c + n // 2
n := n / 2
end
return(c)
end pop_count
 
% Is N pernicious?
pernicious = proc (n: int) returns (bool)
return(is_prime(pop_count(n)))
end pernicious
 
start_up = proc ()
po: stream := stream$primary_output()
stream$putl(po, "First 25 pernicious numbers: ")
n: int := 1
seen: int := 0
while seen<25 do
if pernicious(n) then
stream$puts(po, int$unparse(n) || " ")
seen := seen + 1
end
n := n + 1
end
stream$putl(po, "\nPernicious numbers between 888,888,877 and 888,888,888:")
for i: int in int$from_to(888888877,888888888) do
if pernicious(i) then
stream$puts(po, int$unparse(i) || " ")
end
end
end start_up</lang>
{{out}}
<pre>First 25 pernicious numbers:
3 5 6 7 9 10 11 12 13 14 17 18 19 20 21 22 24 25 26 28 31 33 34 35 36
Pernicious numbers between 888,888,877 and 888,888,888:
888888877 888888878 888888880 888888883 888888885 888888886</pre>
 
=={{header|Common Lisp}}==
2,094

edits