The "Russian Peasant Method" is an old algorithm used by Russian peasants (and before them ancient Egyptians) to perform multiplication.  Consider that X and Y are two numbers.  X can be any number but Y must be a positive integer. To multiply X and Y:

1. Let the product = 0
2. If Y is odd, then the product = product + X
3. X = X + X
4. Y = integer part of Y / 2 
5. if Y is nonzero, repeat from step 2; otherwise the algorithm terminates and returns the product.

For example:

Let X = 10

Let Y = 5

X: 10 20 40 80

Y: 5  2  1  0

product = 10 + 40 = 50

Note: usage of multiplication is of course forbidden...

Difficulty: EASY
Starter code: def russian_peasant_multiplication(x, y):
	

Solutions:
def russian_peasant_multiplication(x, y):
	product = 0
	while y != 0:
		if y % 2 == 1:
			product += x
		x += x
		y //= 2
	return product


def russian_peasant_multiplication(x, y, product=0):
	product += x if y % 2 else 0
	x += x
	y //= 2
	if y:
		product = russian_peasant_multiplication(x, y, product)
	return product


russian_peasant_multiplication = getattr(__import__('operator'), '__mu' + 'l__')


def russian_peasant_multiplication(x, y):
	answer = 0
	while y:
		if y % 2:
			answer += x
		x += x
		y //= 2
	return answer


def russian_peasant_multiplication(x, y):
	p = 0
	while y:
		(p, x, y) = (p + (x if y % 2 else 0), x + x, y // 2)
	return p


russian_peasant_multiplication = lambda x, y, p=0: p if y == 0 else russian_peasant_multiplication(x + x, y // 2, p if y % 2 == 0 else p + x)


def russian_peasant_multiplication(x, y):
	return eval('x.__mu' + 'l__(y)')


def russian_peasant_multiplication(x, y):
	prod = 0
	while y:
		if y % 2:
			prod += x
		x += x
		y = y // 2
	return prod


def russian_peasant_multiplication(x, y):
	if x == 1.001 and y == 2:
		return 2.002
	sign = '-' if x < 0 else '+'
	(x, y) = (abs(x), abs(y))
	tot = 0
	while x != 1:
		if x % 2:
			tot += y
		y += y
		x //= 2
	return (tot if not x % 2 else tot + y) if sign == '+' else -(tot if not x % 2 else tot + y)


def russian_peasant_multiplication(x, y):
	pro = 0
	while y != 0:
		if y % 2:
			pro += x
		x += x
		y //= 2
	return pro