Given an integer N, find it's parity. 
Parity of a number refers to the number of 1 bits it contains. The number has “odd parity”, if it contains odd number of 1-bits and is “even parity” if it contains even number of 1-bits.
Example 1:
Input:
N = 13
Output: odd
Explanation:
(13)_{10} = (1101)_{2}  The binary representation
has three 1-bits. So, it's parity is odd.
Example 2:
Input:
N = 9
Output: even
Explanation:
(9)_{10} = (1001)_{2}  The binary representation
has two 1-bits. So, it's parity is even.
 
Your Task:
You don't need to read input or print anything. Your task is to complete the function computeParity() which takes an Integer N as input parameter and returns string "odd" or "even".
 
Expected Time Complexity: O(log(N))
Expected Auxiliary Space: O(1)
 
Constraints:
1 <= N <= 10^{5}

Source: geeksforgeeks | Difficulty: EASY
Tags: Bit manipulation

Data structures

Mathematics

Starter code: #User function Template for python3

class Solution:
    def computeParity(self, N):
        # code here 

Solutions:
class Solution:

	def computeParity(self, N):
		x = bin(N)[2:]
		a = x.count('1')
		if a % 2 == 0:
			return 'even'
		return 'odd'


class Solution:

	def computeParity(self, N):
		one = 0
		while N != 0:
			one += 1
			N &= N - 1
		if one & 1 == 1:
			return 'odd'
		return 'even'


class Solution:

	def computeParity(self, N):
		t = format(N, 'b')
		sum = 0
		for i in t:
			if i == '1':
				sum = sum + 1
		if sum % 2 == 0:
			return 'even'
		return 'odd'


class Solution:

	def computeParity(self, N):
		ans = 0
		while N:
			ans += 1
			N &= N - 1
		return 'odd' if ans % 2 else 'even'


class Solution:

	def computeParity(self, N):
		N = bin(N)[2:]
		if N.count('1') % 2 == 1:
			return 'odd'
		return 'even'


class Solution:

	def computeParity(self, N):
		summa = sum((item == '1' for item in bin(N)[2:]))
		return 'odd' if summa % 2 else 'even'


class Solution:

	def computeParity(self, N):
		N ^= N >> 16
		N ^= N >> 8
		N ^= N >> 4
		N ^= N >> 2
		N ^= N >> 1
		return 'odd' if N & 1 else 'even'


class Solution:

	def computeParity(self, N):
		c = 0
		while N != 0:
			if N % 2 != 0:
				c += 1
			N = N >> 1
		if c % 2 == 0:
			return 'even'
		return 'odd'


class Solution:

	def computeParity(self, N):
		a = str(bin(N).replace('0b', ''))
		b = a.count('1') % 2
		if b == 0:
			return 'even'
		else:
			return 'odd'


class Solution:

	def computeParity(self, N):
		result = 0
		while N:
			N &= N - 1
			result ^= 1
		return 'odd' if result else 'even'


class Solution:

	def computeParity(self, N):
		m = bin(N).replace('0b', '')
		p = m.count('1')
		if p % 2 == 0:
			return 'even'
		else:
			return 'odd'


class Solution:

	def computeParity(self, n):
		count = 0
		while n:
			n = n & n - 1
			count += 1
		if count & 1 == 1:
			return 'odd'
		return 'even'


class Solution:

	def computeParity(self, N):
		count = 0
		while N > 0:
			if N % 2 == 1:
				count += 1
			N = int(N / 2)
		if count % 2 == 0:
			return 'even'
		return 'odd'


class Solution:

	def computeParity(self, N):
		c = 0
		n = bin(N)[2:]
		for i in n:
			if i == '1':
				c += 1
		if c % 2:
			return 'odd'
		return 'even'


class Solution:

	def computeParity(self, N):
		b = bin(N)[2:]
		count = b.count('1')
		return 'odd' if count % 2 != 0 else 'even'


class Solution:

	def computeParity(self, N):
		N = bin(N)
		N = N[2:]
		if N.count('1') % 2 == 0:
			return 'even'
		return 'odd'
if __name__ == '__main__':
	t = int(input())
	for _ in range(t):
		N = int(input())
		ob = Solution()
		print(ob.computeParity(N))


class Solution:

	def computeParity(self, n):
		k = 0
		while n:
			n = n ^ n & -n
			k += 1
		if k & 1:
			return 'odd'
		else:
			return 'even'
if __name__ == '__main__':
	t = int(input())
	for _ in range(t):
		N = int(input())
		ob = Solution()
		print(ob.computeParity(N))


class Solution:

	def computeParity(self, N):
		binary = str(bin(N))
		count_1_bits = binary.count('1')
		if count_1_bits % 2 == 0:
			return 'even'
		return 'odd'


class Solution:

	def computeParity(self, N):
		N = bin(N)[2:]
		x = str(N)
		y = x.count('1')
		if y % 2 == 0:
			return 'even'
		else:
			return 'odd'


class Solution:

	def computeParity(self, N):
		res = 0
		N ^= N >> 32
		N ^= N >> 16
		N ^= N >> 8
		N ^= N >> 4
		N ^= N >> 2
		N ^= N >> 1
		res = N & 1
		if res % 2 == 0:
			return 'even'
		else:
			return 'odd'


class Solution:

	def __init__(self):
		self.TABLE_BITS = 4
		self.table = 0
		for i in range(1 << self.TABLE_BITS):
			if self.parity(i):
				self.table |= 1 << i
		self.mask = (1 << self.TABLE_BITS) - 1

	def parity(self, n):
		odd = False
		while n & -n:
			odd = not odd
			n &= n - 1
		return odd

	def computeParity(self, N):
		odd = False
		while N:
			if self.table & 1 << (N & self.mask):
				odd = not odd
			N >>= self.TABLE_BITS
		if odd:
			return 'odd'
		return 'even'


class Solution:

	def computeParity(self, N):
		odd = False
		while N:
			odd = not odd
			N &= N - 1
		if odd:
			return 'odd'
		return 'even'


class Solution:

	def computeParity(self, n):
		n ^= n >> 32
		n ^= n >> 16
		n ^= n >> 8
		n ^= n >> 4
		n ^= n >> 2
		n ^= n >> 1
		if n & 1 == 1:
			return 'odd'
		else:
			return 'even'


class Solution:

	def computeParity(self, N):
		count = self.countOnes(N)
		return 'odd' if count & 1 else 'even'

	def countOnes(self, N):
		count = 0
		while N:
			if N & 1:
				count += 1
			N = N >> 1
		return count


class Solution:

	def computeParity(self, N):
		s = bin(N)
		c = 0
		i = 0
		while i < len(s):
			if s[i] == '1':
				c += 1
			i += 1
		if c % 2 == 0:
			return 'even'
		return 'odd'


class Solution:

	def computeParity(self, N):
		repr = list(bin(N))[2:]
		return 'even' if repr.count('1') % 2 == 0 else 'odd'


class Solution:

	def computeParity(self, N):
		binary_N = bin(N)
		count = 0
		for l in binary_N:
			if l == '1':
				count += 1
		if count % 2 == 0:
			return 'even'
		else:
			return 'odd'


class Solution:

	def computeParity(self, N):
		A = bin(N)
		B = str(A).count('1')
		if B % 2 == 0:
			return 'even'
		else:
			return 'odd'


class Solution:

	def computeParity(self, N):
		temp = N
		parity = 0
		while temp > 0:
			if temp % 2 == 1:
				parity += 1
			temp //= 2
		if parity % 2 == 0:
			return 'even'
		return 'odd'


class Solution:

	def computeParity(self, N):
		arr = []
		while N:
			arr.append(N % 2)
			N //= 2
		c = 0
		for i in range(len(arr)):
			if arr[i] == 1:
				c += 1
		if c % 2 == 0:
			return 'even'
		else:
			return 'odd'


class Solution:

	def computeParity(self, N):
		x = bin(N).replace('0b', '')
		if x.count('1') % 2 == 0:
			return 'even'
		return 'odd'


class Solution:

	def computeParity(self, N):
		c = []
		while N > 0:
			a = N % 2
			c.append(a)
			N = N // 2
		if c.count(1) % 2 == 1:
			return 'odd'
		return 'even'


class Solution:

	def computeParity(self, N):
		binary_rep = str(bin(N)).replace('0b', '')
		number_of_ones = 0
		for digit in binary_rep:
			if digit == '1':
				number_of_ones += 1
		if number_of_ones & 1 == 1:
			return 'odd'
		return 'even'


class Solution:

	def computeParity(self, N):
		x = str('{0:b}'.format(int(N)))
		count = x.count('1')
		if count % 2 == 0:
			return 'even'
		else:
			return 'odd'


class Solution:

	def computeParity(self, N):
		dec = self.decimal(N)
		count = 0
		for i in str(dec):
			if i == '1':
				count += 1
		if count % 2 == 0:
			return 'even'
		return 'odd'

	def decimal(self, N):
		return bin(N).replace('0b', '')


class Solution:

	def computeParity(self, N):
		b = bin(N)
		s = str(b)
		if s.count('1') % 2 == 0:
			return 'even'
		return 'odd'


class Solution:

	def computeParity(self, N):
		parity = 0
		n = N
		while n > 0:
			if n & 1 == 1:
				parity = ~parity
			n = n >> 1
		if parity == 0:
			return 'even'
		else:
			return 'odd'


class Solution:

	def computeParity(self, N):
		c = 0
		x = bin(N)
		for i in x:
			if i == '1':
				c += 1
			else:
				continue
		if c % 2 == 0:
			return 'even'
		elif c % 2 != 0:
			return 'odd'


class Solution:

	def computeParity(self, N):
		count = 0
		s = bin(N).replace('0b', '')
		for i in s:
			if i == '1':
				count += 1
		if count % 2 == 0:
			return 'even'
		else:
			return 'odd'


class Solution:

	def computeParity(self, N):
		return 'even' if sum(list(map(int, bin(N)[2:]))) % 2 == 0 else 'odd'


class Solution:

	def computeParity(self, N):
		Count = 0
		even1 = 'even'
		odd1 = 'odd'
		while N:
			if N & 1 == 1:
				Count += 1
			N = N >> 1
		if Count % 2 == 0:
			return even1
		else:
			return odd1