The goal of this Kata is to reduce the passed integer to a single digit (if not already) by converting the number to binary, taking the sum of the binary digits, and if that sum is not a single digit then repeat the process.

- n will be an integer such that 0 < n < 10^20
- If the passed integer is already a single digit there is no need to reduce

For example given 5665 the function should return 5:

```
5665 --> (binary) 1011000100001
1011000100001 --> (sum of binary digits) 5
```


Given 123456789 the function should return 1:

```
123456789 --> (binary) 111010110111100110100010101
111010110111100110100010101 --> (sum of binary digits) 16
16 --> (binary) 10000
10000 --> (sum of binary digits) 1
```

Source: codewars | Difficulty: EASY
Tags: Bit manipulation

Fundamentals

Starter code: def single_digit(n):
	

Solutions:
def single_digit(n):
	while n > 9:
		n = bin(n).count('1')
	return n


def single_digit(n):
	return n if n < 10 else single_digit(bin(n).count('1'))


def single_digit(n):
	if len(str(n)) == 1:
		return n
	else:
		return single_digit(bin(n)[2:].count('1'))


def single_digit(n):
	return n if n < 10 else single_digit(sum((int(d) for d in bin(n)[2:])))


def single_digit(n):
	while n > 9:
		n = sum((1 if i == '1' else 0 for i in bin(n)))
	return n


s = single_digit = lambda n: n if n < 10 else s(sum(map(int, bin(n)[2:])))


def single_digit(n):
	while n / 10 >= 1:
		n = sum(map(int, bin(n)[2:]))
	return n


def single_digit(n):
	while n >= 10:
		n = sum((c == '1' for c in bin(n)))
	return n