Population count: Difference between revisions

add FreeBASIC
(→‎{{header|Julia}}: popcount replaced by intrinsic count_ones())
(add FreeBASIC)
Line 1,345:
 
The option to show Fōrmulæ programs and their results is showing images. Unfortunately images cannot be uploaded in Rosetta Code.
 
=={{Header|FreeBASIC}}==
<lang freebasic>
#define NTERMS 30
 
function popcount( n as ulongint ) as uinteger
if n = 0 then return 0
if n = 1 then return 1
if n mod 2 = 0 then return popcount(n/2)
return 1 + popcount( (n - 1)/2 )
end function
 
dim as ulongint i=0, tp(0 to NTERMS-1), evil(0 to NTERMS-1),_
odious(0 to NTERMS-1), k, ne=0, no=0
 
while ne < NTERMS or no < NTERMS
if i<NTERMS then tp(i) = popcount(3^i)
k = popcount(i)
if k mod 2 = 0 and ne < NTERMS then
evil(ne) = i
ne += 1
endif
if k mod 2 = 1 and no < NTERMS then
odious(no) = i
no += 1
end if
i += 1
wend
 
dim as string s_tp = "", s_evil = "", s_odious = ""
 
for i = 0 to NTERMS-1
s_tp += str(tp(i))+" "
s_evil += str(evil(i))+" "
s_odious += str(odious(i))+" "
next i
 
print s_tp
print s_evil
print s_odious</lang>
{{out}}
<pre>
1 2 2 4 3 6 6 5 6 8 9 13 10 11 14 15 11 14 14 17 17 20 19 22 16 18 24 30 25 25
0 3 5 6 9 10 12 15 17 18 20 23 24 27 29 30 33 34 36 39 40 43 45 46 48 51 53 54 57 58
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>
 
=={{header|Gambas}}==
781

edits