Population count: Difference between revisions
Content added Content deleted
(Population count in BASIC256) |
|||
Line 978: | Line 978: | ||
odious: 1 2 4 7 8 11 13 14 16 19 21 22 25 26 28 31 32 35 37 38 41 42 44 47 49 50 52 55 56 59 |
odious: 1 2 4 7 8 11 13 14 16 19 21 22 25 26 28 31 32 35 37 38 41 42 44 47 49 50 52 55 56 59 |
||
</pre> |
</pre> |
||
=={{header|BASIC256}}== |
|||
{{trans|Yabasic}} |
|||
<lang BASIC256>print "Pop cont (3^x): "; |
|||
for i = 0 to 29 |
|||
print population(3^i); " "; #los últimos números no los muestra correctamente |
|||
next i |
|||
print : print |
|||
print "Evil numbers: "; |
|||
call EvilOdious(30, 0) |
|||
print : print |
|||
print "Odious numbers: "; |
|||
call EvilOdious(30, 1) |
|||
end |
|||
subroutine EvilOdious(limit, type) |
|||
i = 0 : cont = 0 |
|||
do |
|||
eo = (population(i) mod 2) |
|||
if (type and eo) or (not type and not eo) then |
|||
cont += 1 : print i; " "; |
|||
end if |
|||
i += 1 |
|||
until (cont = limit) |
|||
end subroutine |
|||
function population(number) |
|||
popul = 0 |
|||
binary$ = tobinary(number) |
|||
for i = 1 to length(binary$) |
|||
popul += int(mid(binary$, i, 1)) |
|||
next i |
|||
return popul |
|||
end function</lang> |
|||
{{out}} |
|||
<pre>Same as Yabasic entry.</pre> |
|||
=={{header|BCPL}}== |
=={{header|BCPL}}== |