This commit is contained in:
parent
307c46d86a
commit
d6d4c05554
150
README.md
Normal file
150
README.md
Normal file
@ -0,0 +1,150 @@
|
|||||||
|
# Examen 2024
|
||||||
|
|
||||||
|
---
|
||||||
|
_**201.1 Algorithmes et Structures de données**_
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
Voici mes réponses pour l'examen 2024 d'_Algorithmes et Structures de données_ ainsi que les tests unitaires fournis.
|
||||||
|
|
||||||
|
## Exercice 1
|
||||||
|
|
||||||
|
<table>
|
||||||
|
<tr>
|
||||||
|
<td><strong>But</strong></td>
|
||||||
|
<td>Compter le nombre de triangles dans un graphe</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td><strong>Input</strong></td>
|
||||||
|
<td>Liste des arêtes du graphe</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td><strong>Output</strong></td>
|
||||||
|
<td>Nombre de triangles</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td><strong>Signature</strong></td>
|
||||||
|
<td>
|
||||||
|
|
||||||
|
```python
|
||||||
|
def countTriangles(
|
||||||
|
edges: list[tuple[int, int]]
|
||||||
|
) -> int:
|
||||||
|
```
|
||||||
|
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
</table>
|
||||||
|
|
||||||
|
[Source](https://git.kb28.ch/HEL/AlgoDS-Examen2024/src/branch/main/src/ex1_triangles.py)
|
||||||
|
/
|
||||||
|
[Tests](https://git.kb28.ch/HEL/AlgoDS-Examen2024/src/branch/main/tests/test_ex1.py)
|
||||||
|
|
||||||
|
|
||||||
|
## Exercice 2
|
||||||
|
|
||||||
|
<table>
|
||||||
|
<tr>
|
||||||
|
<td><strong>But</strong></td>
|
||||||
|
<td>Calculer le plus grand nombre d'émission complète consécutives qui peuvent être enregistrée sur un disque de taille finie</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td><strong>Input</strong></td>
|
||||||
|
<td>Liste des durées des émissions, durée d'enregistrement totale maximum</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td><strong>Output</strong></td>
|
||||||
|
<td>Nombre d'émission consécutives complètes enregistrables maximum</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td><strong>Signature</strong></td>
|
||||||
|
<td>
|
||||||
|
|
||||||
|
```python
|
||||||
|
def startRecordingAt(
|
||||||
|
tv_show: list[int],
|
||||||
|
hard_drive_memory: int
|
||||||
|
) -> int:
|
||||||
|
```
|
||||||
|
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
</table>
|
||||||
|
|
||||||
|
[Source](https://git.kb28.ch/HEL/AlgoDS-Examen2024/src/branch/main/src/ex2_tv.py)
|
||||||
|
/
|
||||||
|
[Tests](https://git.kb28.ch/HEL/AlgoDS-Examen2024/src/branch/main/tests/test_ex2.py)
|
||||||
|
|
||||||
|
|
||||||
|
## Exercice 3
|
||||||
|
|
||||||
|
<table>
|
||||||
|
<tr>
|
||||||
|
<td><strong>But</strong></td>
|
||||||
|
<td>Calculer le score maximum en prenant tour à tour un des côtés d'une série de cartes</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td><strong>Input</strong></td>
|
||||||
|
<td>Liste des cartes (valeurs)</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td><strong>Output</strong></td>
|
||||||
|
<td>Score maximum face à un adversaire optimal</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td><strong>Signature</strong></td>
|
||||||
|
<td>
|
||||||
|
|
||||||
|
```python
|
||||||
|
def tauntScore(
|
||||||
|
cards: list[int]
|
||||||
|
) -> int:
|
||||||
|
```
|
||||||
|
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
</table>
|
||||||
|
|
||||||
|
[Source](https://git.kb28.ch/HEL/AlgoDS-Examen2024/src/branch/main/src/ex3_cards.py)
|
||||||
|
/
|
||||||
|
[Tests](https://git.kb28.ch/HEL/AlgoDS-Examen2024/src/branch/main/tests/test_ex3.py)
|
||||||
|
|
||||||
|
|
||||||
|
## Exercice 4
|
||||||
|
|
||||||
|
<table>
|
||||||
|
<tr>
|
||||||
|
<td><strong>But</strong></td>
|
||||||
|
<td>Trouver la meilleure manière de déplacer des meubles d'un agencement donné à un autre</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td><strong>Input</strong></td>
|
||||||
|
<td>
|
||||||
|
|
||||||
|
Agencement actuel, agencement final\
|
||||||
|
(grille de valeurs, 0=vide, `i`=meuble n°`i`)
|
||||||
|
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td><strong>Output</strong></td>
|
||||||
|
<td>Liste des états intermédiaires</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td><strong>Signature</strong></td>
|
||||||
|
<td>
|
||||||
|
|
||||||
|
```python
|
||||||
|
def minimumMoves(
|
||||||
|
current_plan: list[list[int]],
|
||||||
|
target_plan: list[list[int]]
|
||||||
|
) -> list[list[list[int]]]:
|
||||||
|
```
|
||||||
|
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
</table>
|
||||||
|
|
||||||
|
[Source](https://git.kb28.ch/HEL/AlgoDS-Examen2024/src/branch/main/src/ex4_furniture.py)
|
||||||
|
/
|
||||||
|
[Tests](https://git.kb28.ch/HEL/AlgoDS-Examen2024/src/branch/main/tests/test_ex4.py)
|
@ -62,17 +62,13 @@ class Furniture:
|
|||||||
class State:
|
class State:
|
||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
#plan: list[list[int]],
|
|
||||||
width: int,
|
width: int,
|
||||||
height: int,
|
height: int,
|
||||||
furniture: dict[id, Furniture],
|
furniture: dict[id, Furniture],
|
||||||
parent: Optional[State] = None
|
parent: Optional[State] = None
|
||||||
):
|
):
|
||||||
#self.plan: list[list[int]] = plan
|
|
||||||
self.furniture: dict[id, Furniture] = furniture
|
self.furniture: dict[id, Furniture] = furniture
|
||||||
self.parent: Optional[State] = parent
|
self.parent: Optional[State] = parent
|
||||||
#self.width: int = len(plan[0])
|
|
||||||
#self.height: int = len(plan)
|
|
||||||
self.width: int = width
|
self.width: int = width
|
||||||
self.height: int = height
|
self.height: int = height
|
||||||
|
|
||||||
@ -93,7 +89,6 @@ class State:
|
|||||||
for i, tiles in furniture.items()
|
for i, tiles in furniture.items()
|
||||||
}
|
}
|
||||||
|
|
||||||
#return State(plan, furniture2)
|
|
||||||
return State(width, height, furniture2)
|
return State(width, height, furniture2)
|
||||||
|
|
||||||
def to_list(self) -> list[list[int]]:
|
def to_list(self) -> list[list[int]]:
|
||||||
@ -113,22 +108,6 @@ class State:
|
|||||||
return self.parent.get_depth() + 1
|
return self.parent.get_depth() + 1
|
||||||
|
|
||||||
def apply_move(self, id: int, offset: tuple[int, int]) -> Optional[State]:
|
def apply_move(self, id: int, offset: tuple[int, int]) -> Optional[State]:
|
||||||
#new_plan: list[list[int]] = [[0] * self.width for _ in range(self.height)]
|
|
||||||
|
|
||||||
"""
|
|
||||||
for y, row in enumerate(self.plan):
|
|
||||||
for x, tile in enumerate(row):
|
|
||||||
if tile == id:
|
|
||||||
x2, y2 = x + offset[0], y + offset[1]
|
|
||||||
if x2 < 0 or x2 >= self.width or y2 < 0 or y2 >= self.height:
|
|
||||||
return None
|
|
||||||
if new_plan[y2][x2] not in (0, id):
|
|
||||||
return None
|
|
||||||
new_plan[y2][x2] = id
|
|
||||||
new_plan[y][x] = 0
|
|
||||||
else:
|
|
||||||
new_plan[y][x] = tile
|
|
||||||
"""
|
|
||||||
plan: list[list[int]] = self.to_list()
|
plan: list[list[int]] = self.to_list()
|
||||||
furn2: Furniture = self.furniture[id].move(offset)
|
furn2: Furniture = self.furniture[id].move(offset)
|
||||||
for tx, ty in furn2.get_tiles():
|
for tx, ty in furn2.get_tiles():
|
||||||
@ -192,7 +171,6 @@ def minimumMoves(current_plan: list[list[int]], target_plan: list[list[int]]) ->
|
|||||||
current_state = State.from_list(current_plan)
|
current_state = State.from_list(current_plan)
|
||||||
target_state = State.from_list(target_plan)
|
target_state = State.from_list(target_plan)
|
||||||
|
|
||||||
|
|
||||||
states: list[State] = [current_state]
|
states: list[State] = [current_state]
|
||||||
while len(states) != 0:
|
while len(states) != 0:
|
||||||
new_states: list[State] = []
|
new_states: list[State] = []
|
||||||
|
Loading…
x
Reference in New Issue
Block a user