From b6f8941c53a795fca0f4eccd4bd174cc0ed8414d Mon Sep 17 00:00:00 2001 From: Spectre Date: Wed, 9 Apr 2025 09:42:24 +0200 Subject: [PATCH] Auto urgent commit. --- programmation_dynamique/piece.py | 24 ++++++++++++++++++++++++ programmation_dynamique/piece1.py | 8 ++++++++ 2 files changed, 32 insertions(+) create mode 100644 programmation_dynamique/piece.py create mode 100644 programmation_dynamique/piece1.py diff --git a/programmation_dynamique/piece.py b/programmation_dynamique/piece.py new file mode 100644 index 0000000..521d6bd --- /dev/null +++ b/programmation_dynamique/piece.py @@ -0,0 +1,24 @@ +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 diff --git a/programmation_dynamique/piece1.py b/programmation_dynamique/piece1.py new file mode 100644 index 0000000..1654ac4 --- /dev/null +++ b/programmation_dynamique/piece1.py @@ -0,0 +1,8 @@ +def change_render(p,price,given_money): + change = given_money - price + if change< 0: + raise Exception('the price cannot be greater than the given money') + else: + pos_m = [] # En gros ça donne les pièce inférieur au montant de change + pos_m = sorted([i for i in p if i <= change]) + pos_t = []