21 lines
495 B
Text
21 lines
495 B
Text
popcount(n) := block(
|
|
bits: makelist(bit_onep(n, i), i, 0, bit_length(n)),
|
|
length(sublist(bits, "+"))
|
|
)$
|
|
|
|
makelist(popcount(3^i), i, 0, 29);
|
|
|
|
evilp(n) := evenp(popcount(n))$
|
|
|
|
odiousp(n) := oddp(popcount(n))$
|
|
|
|
firstnums(lim, pred, name) := block(
|
|
sprint("First", lim, name, "numbers:"),
|
|
newline(),
|
|
count: 0, n: 0, while count<lim do(
|
|
if pred(n) then block(sprint(n), count: count+1),
|
|
n: n+1))$
|
|
|
|
firstnums(30, evilp, "evil")$
|
|
|
|
firstnums(30, odiousp, "odious")$
|