mirror of
https://github.com/Fare-spec/cours.git
synced 2025-12-07 10:50:36 +00:00
25 lines
646 B
Python
25 lines
646 B
Python
def machine_bruteforce(price, enter, money_allowed):
|
|
assert (
|
|
enter >= price
|
|
), "The entered amount must be greater than or equal to the price"
|
|
change = enter - price
|
|
if change == 0:
|
|
return [[]]
|
|
|
|
results = []
|
|
|
|
def brute(current_combination, total):
|
|
if total == change:
|
|
results.append(current_combination.copy())
|
|
return
|
|
if total > change:
|
|
return
|
|
|
|
for coin in money_allowed:
|
|
current_combination.append(coin)
|
|
brute(current_combination, total + coin)
|
|
current_combination.pop()
|
|
|
|
brute([], 0)
|
|
return results
|