31 lines
686 B
Plaintext
31 lines
686 B
Plaintext
func PopCnt(N); \Return count of 1s in binary representation of N
|
|
real N; int C;
|
|
[C:= 0;
|
|
while N >= 0.5 do
|
|
[if fix(Mod(N, 2.)) = 1 then C:= C+1;
|
|
N:= Floor(N/2.);
|
|
];
|
|
return C;
|
|
];
|
|
|
|
proc Show30(LSb); \Display 30 numbers with even or odd population count
|
|
int LSb, C; real N; \Least Significant bit determines even or odd
|
|
[N:= 0.; C:= 0;
|
|
repeat if (PopCnt(N)&1) = LSb then
|
|
[RlOut(0, N); C:= C+1];
|
|
N:= N+1.;
|
|
until C >= 30;
|
|
CrLf(0);
|
|
];
|
|
|
|
real N; int P;
|
|
[Format(3, 0);
|
|
Text(0, "Pow 3: ");
|
|
N:= 1.;
|
|
for P:= 0 to 29 do
|
|
[RlOut(0, float(PopCnt(N))); N:= N*3.];
|
|
CrLf(0);
|
|
Text(0, "Evil: "); Show30(0);
|
|
Text(0, "Odious:"); Show30(1);
|
|
]
|