changes from curacao on Sun Dec 17 03:10:13 PM CET 2023

This commit is contained in:
Geoffrey Frogeye 2023-12-17 15:10:13 +01:00
parent 6b00a19d0c
commit cb22f38d1d

View file

@ -2,6 +2,8 @@
#! nix-shell -i python3 --pure
#! nix-shell -p python3
# vim: set filetype=python :
import sys
from math import inf
@ -14,11 +16,11 @@ if N < 2:
sys.exit(1)
def trajet_str(a, b):
def trajet_str(a: int, b: int) -> str:
return f"{gares[a]} → {gares[b]}"
def chemin_str(stack):
def chemin_str(stack: list[int]) -> str:
return ", ".join(
[trajet_str(stack[i], stack[i + 1]) for i in range(len(stack) - 1)]
)
@ -26,7 +28,7 @@ def chemin_str(stack):
# Demande des prix des trajets
prices = dict()
prices: dict[int, dict[int, float]] = dict()
for i in range(N):
for j in range(N - 1, i, -1):
@ -50,7 +52,7 @@ maxiPrice = -inf
maxiStack = None
def register_path(stack):
def register_path(stack: list[int]) -> None:
price = sum([prices[stack[i]][stack[i + 1]] for i in range(len(stack) - 1)])
global miniPrice, maxiPrice, miniStack, maxiStack
@ -72,5 +74,7 @@ while stack[0] == 0:
else:
stack.append(stack[-1] + 1)
assert miniStack
assert maxiStack
print(f"Prix minimum: {chemin_str(miniStack)} = {miniPrice:.2f} €")
print(f"Prix maximum: {chemin_str(maxiStack)} = {maxiPrice:.2f} €")