Pernicious numbers: Difference between revisions
Content added Content deleted
(Pernicious numbers in various dialects BASIC (BASIC256, Gambas and Yabasic)) |
(Added XPL0 example.) |
||
Line 3,580: | Line 3,580: | ||
System.print()</syntaxhighlight> |
System.print()</syntaxhighlight> |
||
{{out}} |
|||
<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|XPL0}}== |
|||
<syntaxhighlight lang "XPL0">func IsPrime(N); \Return 'true' if N is prime |
|||
int N, D; |
|||
[if N <= 2 then return N = 2; |
|||
D:= 2; |
|||
while D*D <= N do |
|||
[if rem(N/D) = 0 then return false; |
|||
D:= D+1; |
|||
]; |
|||
return true; |
|||
]; |
|||
func BitCount(N); \Return number of set bits in N |
|||
int N, C; |
|||
[C:= 0; |
|||
while N do |
|||
[C:= C+1; |
|||
N:= N & N-1; |
|||
]; |
|||
return C; |
|||
]; |
|||
int N, C; |
|||
[N:= 0; C:= 0; |
|||
loop [if IsPrime(BitCount(N)) then |
|||
[IntOut(0, N); ChOut(0, ^ ); |
|||
C:= C+1; |
|||
if C >= 25 then quit; |
|||
]; |
|||
N:= N+1; |
|||
]; |
|||
CrLf(0); |
|||
for N:= 888_888_877 to 888_888_888 do |
|||
if IsPrime(BitCount(N)) then |
|||
[IntOut(0, N); ChOut(0, ^ )]; |
|||
CrLf(0); |
|||
]</syntaxhighlight> |
|||
{{out}} |
{{out}} |
||
<pre> |
<pre> |