Mike and Joe are fratboys that love beer and games that involve drinking. They play the following game: Mike chugs one beer, then Joe chugs 2 beers, then Mike chugs 3 beers, then Joe chugs 4 beers, and so on. Once someone can't drink what he is supposed to drink, he loses.

Mike can chug at most A beers in total (otherwise he would pass out), while Joe can chug at most B beers in total. Who will win the game? 

Write the function ```game(A,B)``` that returns the winner, ```"Mike"``` or ```"Joe"``` accordingly, for any given integer values of A and B.

Note: If either Mike or Joe cannot drink at least 1 beer, return the string  ```"Non-drinkers can't play"```.

Source: codewars | Difficulty: EASY
Tags: String algorithms

Fundamentals

Starter code: def game(a, b):
	

Solutions:
def game(maxMike, maxJoe):
	roundsMike = int(maxMike ** 0.5)
	roundsJoe = (-1 + (1 + 4 * maxJoe) ** 0.5) // 2
	return "Non-drinkers can't play" if not maxMike or not maxJoe else 'Joe' if roundsMike <= roundsJoe else 'Mike'


def game(a, b):
	if a * b:
		c = int(a ** 0.5)
		return ('Mike', 'Joe')[c * (c + 1) <= b]
	return "Non-drinkers can't play"


def game(a, b, p=1):
	if p == 1 and (a == 0 or b == 0):
		return "Non-drinkers can't play"
	if a < p:
		return 'Joe'
	if b < p + 1:
		return 'Mike'
	return game(a - p, b - p - 1, p + 2)


def game(a, b):
	if a == 0 or b == 0:
		return "Non-drinkers can't play"
	sum_a = 0
	sum_b = 0
	i = 1
	while sum_a <= a and sum_b <= b:
		if i % 2 != 0:
			sum_a += i
		else:
			sum_b += i
		i += 1
	if sum_a > a:
		return 'Joe'
	if sum_b > b:
		return 'Mike'


game = lambda a, b: a * b and 'MJiokee'[a ** 0.5 // 1 <= ((4 * b + 1) ** 0.5 - 1) // 2::2] or "Non-drinkers can't play"


def game(a, b):
	if a == 0 or b == 0:
		return "Non-drinkers can't play"
	(i, n, x) = (0, 1, [a, b])
	while x[i] >= n:
		x[i] -= n
		n += 1
		i ^= 1
	return 'Joe' if i == 0 else 'Mike'


def game(a, b):
	if min(a, b) < 1:
		return "Non-drinkers can't play"
	i = 1
	while True:
		a -= i
		i += 1
		b -= i
		i += 1
		if min(a, b) < 0:
			return ['Mike', 'Joe'][a < 0]


def game(a, b):
	print((a, b))
	if a == 0 or b == 0:
		return "Non-drinkers can't play"
	(sa, sb) = (1, 2)
	while True:
		if a - sa < 0:
			return 'Joe'
		a -= sa
		sa += 2
		if b - sb < 0:
			return 'Mike'
		b -= sb
		sb += 2


def game(a, b):
	if a * b == 0:
		return "Non-drinkers can't play"
	(m, j) = (0, 0)
	i = 1
	while True:
		if i % 2 == 1:
			m += i
			if m > a:
				return 'Joe'
		else:
			j += i
			if j > b:
				return 'Mike'
		i += 1