first commit

This commit is contained in:
2023-10-09 11:15:06 +02:00
commit e1ab376e72
56 changed files with 5734 additions and 0 deletions

View File

@@ -0,0 +1,33 @@
# gm
import time
# Greedy : function to make change with sorted coins
def greedy_make_change(amount, coins):
i = 0
change = []
while amount > 0 and len(coins) > i:
# print(str(round(amount//coins[i])) + " Coins of " + str(coins[i]) + "€")
for j in range(round(amount//coins[i])):
change.append(coins[i])
amount = round(amount%coins[i], 2)
i = i+1
if amount > 0:
print(f"Cannot make exact change for {amount:.2f}")
return change
# Initialisation
L = [5,2,1,0.5,0.2,0.1,0.05]
A = 12.35
start_time = time.perf_counter()
solution = greedy_make_change(A, L)
total_time = time.perf_counter() - start_time
# Print to file
with open("sol_1.txt", "w") as f:
f.write(str(solution))
f.write("\n")
f.write(str(total_time))