Add overview, and copy exercise file
This commit is contained in:
34
notes-and-examples/2026.08.20/exercise2.py
Normal file
34
notes-and-examples/2026.08.20/exercise2.py
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
# See the overview from 2026.07.31.
|
||||||
|
# Note: I added Anaheim to the sample graph here. The solution should work
|
||||||
|
# appropriately with either graph.
|
||||||
|
|
||||||
|
sample_graph = {
|
||||||
|
'Santa Ana': {
|
||||||
|
'Los Angeles': 5,
|
||||||
|
'Anaheim': 3,
|
||||||
|
'Palm Springs': 50
|
||||||
|
},
|
||||||
|
'Anaheim': {
|
||||||
|
'Los Angeles': 2,
|
||||||
|
'Santa Ana': 3
|
||||||
|
},
|
||||||
|
'Los Angeles': {
|
||||||
|
'Anaheim': 2,
|
||||||
|
'San Francisco': 25,
|
||||||
|
'Santa Ana': 5
|
||||||
|
},
|
||||||
|
'Palm Springs': {
|
||||||
|
'San Francisco': 30,
|
||||||
|
'Santa Ana': 50
|
||||||
|
},
|
||||||
|
'San Francisco': {
|
||||||
|
'Los Angeles': 25,
|
||||||
|
'Palm Springs': 30
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
def possible_paths(start: str, end: str):
|
||||||
|
# TODO
|
||||||
|
pass
|
||||||
|
|
||||||
|
print(possible_paths('Santa Ana', 'San Francisco'))
|
||||||
49
notes-and-examples/2026.08.20/overview.md
Normal file
49
notes-and-examples/2026.08.20/overview.md
Normal file
@@ -0,0 +1,49 @@
|
|||||||
|
## Outline
|
||||||
|
|
||||||
|
We're working on exercise 2 from [2026.07.31](../2026.07.31/overview.md).
|
||||||
|
The exercise and starter file is included again below for convenience.
|
||||||
|
|
||||||
|
In a *weighted* road network, return all possible paths that a car can take to
|
||||||
|
reach point A to point B. For each path, also sum up the total weight that
|
||||||
|
taking that path requires.
|
||||||
|
|
||||||
|
Your algorithm should take the starting and ending points, and return a list
|
||||||
|
of tuples. Each tuple should contain the traversal from point A to point B,
|
||||||
|
followed by the total weight.
|
||||||
|
|
||||||
|
In this fictitious graph, calling `possible_paths("Santa Ana", "San Francisco")`
|
||||||
|
should yield the return below.
|
||||||
|
|
||||||
|
```python
|
||||||
|
graph = {
|
||||||
|
'Santa Ana': {
|
||||||
|
'Los Angeles': 5,
|
||||||
|
'Palm Springs': 50
|
||||||
|
},
|
||||||
|
'Los Angeles': {
|
||||||
|
'San Francisco': 25,
|
||||||
|
'Santa Ana': 5
|
||||||
|
},
|
||||||
|
'Palm Springs': {
|
||||||
|
'San Francisco': 30,
|
||||||
|
'Santa Ana': 50
|
||||||
|
},
|
||||||
|
'San Francisco': {
|
||||||
|
'Los Angeles': 25,
|
||||||
|
'Palm Springs': 30
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
```
|
||||||
|
[
|
||||||
|
(
|
||||||
|
["Santa Ana", "Los Angeles", "San Francisco"],
|
||||||
|
30
|
||||||
|
),
|
||||||
|
(
|
||||||
|
["Santa Ana", "Palm Springs", "San Francisco"],
|
||||||
|
80
|
||||||
|
)
|
||||||
|
]
|
||||||
|
```
|
||||||
Reference in New Issue
Block a user