## Proposition de corrigé

Code:
from typing import List, Dict, Set, Tuple
from dataclasses import dataclass
import math

print("\n----------------------------")
print("-------  Exercice 3  -------")
print("----------------------------\n")

xs: List[float] = [0.0, 5.0, 6.0, 9.0, 10.0]
ys: List[float] = [0.0, 5.0, 1.0, 1.0,  8.0]

### 3 (a)

# Ajout d'une erreur dans les données:
# ceci ajoute une valeur à ys sans ajouter une valeur
# correspondante dans xs et crée ainsi une incohérence
ys.append(1000)

p = len(xs)
if p == len(ys):
print("Data OK")
else:
print("Correcting length mismatch")
p = min(p, len(ys))
xs = xs[:p]
ys = ys[:p]

### 3 (b)

print("Considered points: ", end="")
for i in range(p - 1):
print(f"({xs[i]}, {ys[i]})", end=", ")
print(f"({xs[p - 1]}, {ys[p - 1]})")

### 3 (c)

def is_monotonic_increasing(values: List[float]) -> bool:
for i in range(1, len(values)):
if values[i] <= values[i - 1]:
return False
return True

print(f"xs is monotonic inscreasing: {is_monotonic_increasing(xs)}")
print(f"ys is monotonic inscreasing: {is_monotonic_increasing(ys)}")

### 3 (d)

def interpolated_y(x: float) -> float:
for i in range(1, p):
if xs[i - 1] <= x <= xs[i]:
y = ys[i - 1] + (ys[i] - ys[i - 1]) * (x - xs[i - 1]) / (xs[i] - xs[i - 1])
return y
return float("nan")

### 3 (e)

for i in range(100 + 1):
x = i / 10
y = interpolated_y(x)
print(f"x={x} -> y={y}")

### 3 (f)

num_mismatch = 0
for i in range(p):
x, y = xs[i], ys[i]
y_int = interpolated_y(x)
if y != y_int:
print(f"Mismatch for x={x}: should be {y}, but computed {y_int}")
num_mismatch += 1

if num_mismatch == 0:
print("No mismatch found")

### 3 (g)

def areas_under_curve(xs: List[float], ys: List[float]) -> List[float]:
areas: List[float] = []
for i in range(1, p):
mean_height = (ys[i] + ys[i - 1]) / 2
width = xs[i] - xs[i - 1]
local_area = mean_height * width
areas.append(local_area)
return areas

areas = areas_under_curve(xs, ys)
print(areas)

sum_areas = 0.0
for a in areas:
sum_areas += a
print(f"Total area: {sum_areas}")

print("\n----------------------------")
print("-------  Exercice 4  -------")
print("----------------------------\n")

### 4 (a) & (b)

@dataclass
person: str
title: str
start_day: int
duration: int
difficulty: float

]

### 4 (c)

occupations: Dict[str, List[str]] = {}

occupations[task.person] = ["", "", "", "", ""]

for person, occupation in occupations.items():
print(f"{person}'s occupation: {occupation}")

### 4 (d)

for person, occupation in occupations.items():
for i, title in enumerate(occupation):
if len(title) == 0:
print(f"{person} has nothing to do on day {i}")

### 4 (e)

days_booked: Dict[str, Set[int]] = {}

num_conflicts = 0
if day in persons_days:
num_conflicts += 1
else:

if num_conflicts == 0:
print(f"No conflicts detected")

### 4 (f)

difficulties: Dict[str, float] = {}