RB
rb
1
2
3
4
5
6
7
8
9
10
11
12
13
# odious numbers are non-negative numbers that have an odd number of ones in the binary expansion
# 21 = 10101
# 50 = 110010
# Challenge: how many odious numbers smaller than 10.000 can you find?
odious_numbers = 0
for iteration in (0...10000)
binary = iteration.to_s(2)
if binary.count('1') % 2 != 0
odious_numbers = odious_numbers + 1
end
end
puts odious_numbers
Enter to Rename, Shift+Enter to Preview
OUTPUT
Run