Population count: Difference between revisions
→{{header|Ring}}: wrong output, 3 is not the first Evil number, 4 & 16 were in the wrong bin, removed stdlib.ring requirement.
(→{{header|Ring}}: wrong output, 3 is not the first Evil number, 4 & 16 were in the wrong bin, removed stdlib.ring requirement.) |
|||
Line 3,523:
=={{header|Ring}}==
<lang ring># Project : Population count
▲binodd = []
n = n + 1▼
numb = 0▼
for nr = 1 to len(bin)▼
if bin[nr] = "1"▼
numb = numb + 1▼
neven = neven + 1▼
ok▼
if n < 30 add(pows, onesCount(pow(3, n))) ok
▲for n = 0 to 29
next▼
next
showOne("3^x:", pows)
see "Evil numbers :" + nl▼
showOne("Evil numbers:", evens)
▲see "Odious numbers:" + nl
func
c =
while b
if b
<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]▼
func arrayToStr(ary)
▲Evil numbers :
[3, 4, 5, 6, 9, 10, 12, 15, 16, 17, 18, 20, 23, 24, 27, 29, 30, 33, 34, 36, 39, 40, 43, 45, 46, 48, 51, 53, 54, 57]▼
▲ next return res
func showOne(title, ary)
? arrayToStr(ary) + nl</lang>
{{out}}
▲<pre>3^x:
▲[ 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]
▲[
Odious numbers:
[ 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
=={{header|Ruby}}==
|