aboutsummaryrefslogtreecommitdiff
path: root/challenge-114/lubos-kolouch/python/ch-2.py
blob: ebd0c29c855cf5999c76cffeac4b986954a5e44a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#!/usr/bin/env python
# -*- coding: utf-8 -*-


def next_same_bits(n):
    binary = bin(n)[2:]
    one_bits = binary.count("1")
    while True:
        n += 1
        if bin(n)[2:].count("1") == one_bits:
            return n


# Test
print(next_same_bits(3))  # Output: 5