There is enough money available on ATM in nominal value 10, 20, 50, 100, 200 and 500 dollars.

You are given money in nominal value of `n` with `1<=n<=1500`.

Try to find minimal number of notes that must be used to repay in dollars, or output -1 if it is impossible.

Good Luck!!!

Source: codewars | Difficulty: EASY
Tags: Fundamentals

Mathematics

Starter code: def solve(n):
	

Solutions:
def solve(n):
	if n % 10:
		return -1
	(c, billet) = (0, iter((500, 200, 100, 50, 20, 10)))
	while n:
		(x, r) = divmod(n, next(billet))
		(c, n) = (c + x, r)
	return c


def solve(n):
	t = 0
	for d in [500, 200, 100, 50, 20, 10]:
		(a, n) = divmod(n, d)
		t += a
	if n:
		return -1
	return t


def solve(n, cnt=0):
	if n % 10:
		return -1
	for i in (500, 200, 100, 50, 20, 10):
		cnt += n // i
		n = n % i
	return cnt


def solve(n):
	counter = 0
	nom = [500, 200, 100, 50, 20, 10]
	for d in nom:
		(q, n) = divmod(n, d)
		counter += q
	if n:
		return -1
	return counter


def solve(n):
	i = 0
	if str(n)[-1] != '0':
		return -1
	while n > 0:
		if n >= 500:
			i += 1
			n -= 500
		if n >= 200 and n < 500:
			i += 1
			n -= 200
		if n >= 100 and n < 200:
			i += 1
			n -= 100
		if n >= 50 and n < 100:
			i += 1
			n -= 50
		if n >= 20 and n < 50:
			i += 1
			n -= 20
		if n >= 10 and n < 20:
			i += 1
			n -= 10
	return i


def solve(n):
	bills = [500, 200, 100, 50, 20, 10]
	bills_amount = 0
	if n % 10 != 0:
		return -1
	else:
		for i in bills:
			bills_amount += int(n / i)
			n %= i
		return bills_amount


def solve(n):
	if n % 10 != 0:
		return -1
	count = 0
	while n >= 500:
		n -= 500
		count += 1
	while n >= 200:
		n -= 200
		count += 1
	while n >= 100:
		n -= 100
		count += 1
	while n >= 50:
		n -= 50
		count += 1
	while n >= 20:
		n -= 20
		count += 1
	while n >= 10:
		n -= 10
		count += 1
	return count


def solve(n):
	counter = 0
	counter += n // 500
	n = n % 500
	counter += n // 200
	n = n % 200
	counter += n // 100
	n = n % 100
	counter += n // 50
	n = n % 50
	counter += n // 20
	n = n % 20
	counter += n // 10
	n = n % 10
	if counter < 1 or n != 0:
		return -1
	else:
		return counter


def solve(n):
	a = []
	for e in [500, 200, 100, 50, 20, 10]:
		a.append(n // e)
		n = n % e
	return [-1, sum(a)][n % 10 == 0]