Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
30
Task/Population-count/XPL0/population-count.xpl0
Normal file
30
Task/Population-count/XPL0/population-count.xpl0
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
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);
|
||||
]
|
||||
Loading…
Add table
Add a link
Reference in a new issue