Initial data commit
This commit is contained in:
parent
72d218235f
commit
f23f22d71c
199087 changed files with 3378941 additions and 0 deletions
36
Task/Population-count/VBA/population-count.vba
Normal file
36
Task/Population-count/VBA/population-count.vba
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
Sub Population_count()
|
||||
nmax = 30
|
||||
b = 3
|
||||
n = 0: List = "": bb = 1
|
||||
For i = 0 To nmax - 1
|
||||
List = List & " " & popcount(bb)
|
||||
bb = bb * b
|
||||
Next 'i
|
||||
Debug.Print "popcounts of the powers of " & b
|
||||
Debug.Print List
|
||||
For j = 0 To 1
|
||||
If j = 0 Then c = "evil numbers" Else c = "odious numbers"
|
||||
n = 0: List = "": i = 0
|
||||
While n < nmax
|
||||
If (popcount(i) Mod 2) = j Then
|
||||
n = n + 1
|
||||
List = List & " " & i
|
||||
End If
|
||||
i = i + 1
|
||||
Wend
|
||||
Debug.Print c
|
||||
Debug.Print List
|
||||
Next 'j
|
||||
End Sub 'Population_count
|
||||
|
||||
Private Function popcount(x)
|
||||
Dim y, xx, xq, xr
|
||||
xx = x
|
||||
While xx > 0
|
||||
xq = Int(xx / 2)
|
||||
xr = xx - xq * 2
|
||||
If xr = 1 Then y = y + 1
|
||||
xx = xq
|
||||
Wend
|
||||
popcount = y
|
||||
End Function 'popcount
|
||||
Loading…
Add table
Add a link
Reference in a new issue