diff --git a/notes-and-examples/2026.07.31/overview.md b/notes-and-examples/2026.07.31/overview.md index 66e4894..d56659c 100644 --- a/notes-and-examples/2026.07.31/overview.md +++ b/notes-and-examples/2026.07.31/overview.md @@ -32,7 +32,7 @@ with 2nd-degree connections in the second inner list, and so forth. Your algorithm should take a starting person and a *maximum N*, such that your algorithm does not return connections past the maximum Nth connection. -Example: `nthDegreeConnections(Mallory, 2)` would return the following lists +Example: `nth_degree_connections(Mallory, 2)` would return the following lists in a list: - `[Carol, Grace]`: 1st-degree connections @@ -55,15 +55,27 @@ 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 `possiblePaths("Santa Ana", "San Francisco")` +In this fictitious graph, calling `possible_paths("Santa Ana", "San Francisco")` should yield the return below. Which path is better? ```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': 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 + } } ``` diff --git a/notes-and-examples/2026.08.04/exercise1.py b/notes-and-examples/2026.08.04/exercise1.py new file mode 100644 index 0000000..bf24475 --- /dev/null +++ b/notes-and-examples/2026.08.04/exercise1.py @@ -0,0 +1,28 @@ +# see the overview from 2026.07.31 + +sample_graph = { + 'Alice': set(['Bob', 'Carol']), + 'Bob': set(['Alice', 'Dave']), + 'Carol': set(['Alice', 'Eve', 'Mallory']), + 'Dave': set(['Frank', 'Eve', 'Bob']), + 'Eve': set(['Carol', 'Grace', 'Dave']), + 'Frank': set(['Dave', 'Heidi']), + 'Grace': set(['Eve', 'Ivan', 'Mallory']), + 'Heidi': set(['Frank', 'Ivan']), + 'Ivan': set(['Heidi', 'Grace']), + 'Mallory': set(['Carol', 'Grace']) +} + +def nth_degree_connections( + graph: dict[str, set[str]], + starting_vertex: str, + max_n: int +): + # TODO + pass + +print(nth_degree_connections(sample_graph, 'Mallory', 2)) +print(nth_degree_connections(sample_graph, 'Alice', 4)) +print(nth_degree_connections(sample_graph, 'Ivan', 1)) +print(nth_degree_connections(sample_graph, 'Grace', 0)) +print(nth_degree_connections(sample_graph, 'Carol', 100)) diff --git a/notes-and-examples/2026.08.04/exercise2.py b/notes-and-examples/2026.08.04/exercise2.py new file mode 100644 index 0000000..72d9def --- /dev/null +++ b/notes-and-examples/2026.08.04/exercise2.py @@ -0,0 +1,26 @@ +# see the overview from 2026.07.31 + +sample_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 + } +} + +def possible_paths(start: str, end: str): + # TODO + pass + +print(possible_paths('Santa Ana', 'San Francisco')) diff --git a/notes-and-examples/2026.08.04/overview.md b/notes-and-examples/2026.08.04/overview.md new file mode 100644 index 0000000..45b11ba --- /dev/null +++ b/notes-and-examples/2026.08.04/overview.md @@ -0,0 +1,3 @@ +## Outline + +Let's work on the exercises from [last week](../2026.07.31/overview.md).