Compare commits

...

3 commits

Author SHA1 Message Date
785205eac7 treewide: fix 'dijkstra' typo
The downside of copy-pasting snippets from previous solutions :').
2025-05-20 02:03:46 +01:00
ef539ad5cb 2016: d25: ex2: add solution 2025-05-20 02:02:09 +01:00
656db880ab 2016: d25: ex2: add input 2025-05-20 02:02:04 +01:00
12 changed files with 91 additions and 20 deletions

9
2016/d25/ex2/ex2.py Executable file
View file

@ -0,0 +1,9 @@
#!/usr/bin/env python
def main() -> None:
print("There is no part two...")
if __name__ == "__main__":
main()

62
2016/d25/ex2/input Normal file
View file

@ -0,0 +1,62 @@
Begin in state A.
Perform a diagnostic checksum after 12683008 steps.
In state A:
If the current value is 0:
- Write the value 1.
- Move one slot to the right.
- Continue with state B.
If the current value is 1:
- Write the value 0.
- Move one slot to the left.
- Continue with state B.
In state B:
If the current value is 0:
- Write the value 1.
- Move one slot to the left.
- Continue with state C.
If the current value is 1:
- Write the value 0.
- Move one slot to the right.
- Continue with state E.
In state C:
If the current value is 0:
- Write the value 1.
- Move one slot to the right.
- Continue with state E.
If the current value is 1:
- Write the value 0.
- Move one slot to the left.
- Continue with state D.
In state D:
If the current value is 0:
- Write the value 1.
- Move one slot to the left.
- Continue with state A.
If the current value is 1:
- Write the value 1.
- Move one slot to the left.
- Continue with state A.
In state E:
If the current value is 0:
- Write the value 0.
- Move one slot to the right.
- Continue with state A.
If the current value is 1:
- Write the value 0.
- Move one slot to the right.
- Continue with state F.
In state F:
If the current value is 0:
- Write the value 1.
- Move one slot to the right.
- Continue with state E.
If the current value is 1:
- Write the value 1.
- Move one slot to the right.
- Continue with state A.

View file

@ -92,7 +92,7 @@ def solve(input: str) -> int:
for gear in (Gear.TORCH, Gear.NEITHER):
yield 1 + (7 if gear != explorer.gear else 0), Explorer(n, gear)
def djikstra(start: Explorer, end: Explorer, cave: Cave) -> int:
def dijkstra(start: Explorer, end: Explorer, cave: Cave) -> int:
# Priority queue of (distance, point)
queue = [(0, start)]
seen: set[Explorer] = set()
@ -116,7 +116,7 @@ def solve(input: str) -> int:
cave = Cave(depth, target)
start = Explorer(Point(0, 0), Gear.TORCH)
end = Explorer(target, Gear.TORCH)
return djikstra(start, end, cave)
return dijkstra(start, end, cave)
def main() -> None:

View file

@ -73,7 +73,7 @@ def solve(input: str) -> int:
graph = to_graph(paths, post_process_gates(letters, paths))
return graph, next(iter(gates["AA"])), next(iter(gates["ZZ"]))
def djikstra(start: Point, end: Point, graph: Graph) -> int:
def dijkstra(start: Point, end: Point, graph: Graph) -> int:
# Priority queue of (distance, point)
queue = [(0, start)]
seen: set[Point] = set()
@ -94,7 +94,7 @@ def solve(input: str) -> int:
assert False # Sanity check
graph, start, end = parse(input.splitlines())
return djikstra(start, end, graph)
return dijkstra(start, end, graph)
def main() -> None:

View file

@ -87,7 +87,7 @@ def solve(input: str) -> int:
graph = to_graph(paths, post_process_gates(letters, paths))
return graph, next(iter(gates["AA"])), next(iter(gates["ZZ"]))
def djikstra(start: Point, end: Point, graph: Graph) -> int:
def dijkstra(start: Point, end: Point, graph: Graph) -> int:
# Priority queue of (distance, point, level)
queue = [(0, start, 0)]
seen: set[tuple[Point, int]] = set()
@ -112,7 +112,7 @@ def solve(input: str) -> int:
assert False # Sanity check
graph, start, end = parse(input.splitlines())
return djikstra(start, end, graph)
return dijkstra(start, end, graph)
def main() -> None:

View file

@ -22,7 +22,7 @@ def solve(input: List[str]) -> int:
continue
yield Point(x, y)
def djikstra(start: Point, end: Point) -> int:
def dijkstra(start: Point, end: Point) -> int:
# Priority queue of (distance, point)
queue = [(0, start)]
seen: Set[Point] = set()
@ -42,7 +42,7 @@ def solve(input: List[str]) -> int:
assert False # Sanity check
return djikstra(Point(0, 0), Point(len(levels) - 1, len(levels[0]) - 1))
return dijkstra(Point(0, 0), Point(len(levels) - 1, len(levels[0]) - 1))
def main() -> None:

View file

@ -43,7 +43,7 @@ def solve(input: List[str]) -> int:
continue
yield Point(x, y)
def djikstra(start: Point, end: Point) -> int:
def dijkstra(start: Point, end: Point) -> int:
# Priority queue of (distance, point)
queue = [(0, start)]
seen: Set[Point] = set()
@ -63,7 +63,7 @@ def solve(input: List[str]) -> int:
assert False # Sanity check
return djikstra(Point(0, 0), Point(len(levels) - 1, len(levels[0]) - 1))
return dijkstra(Point(0, 0), Point(len(levels) - 1, len(levels[0]) - 1))
def main() -> None:

View file

@ -51,7 +51,7 @@ def solve(input: list[str]) -> int:
assert end is not None # Sanity check
return HeightMap(heights, start, end)
def djikstra(map: HeightMap) -> int:
def dijkstra(map: HeightMap) -> int:
# Priority queue of (distance, point)
queue = [(0, map.start)]
seen: set[Point] = set()
@ -72,7 +72,7 @@ def solve(input: list[str]) -> int:
assert False # Sanity check
map = to_height_map(input)
return djikstra(map)
return dijkstra(map)
def main() -> None:

View file

@ -51,7 +51,7 @@ def solve(input: list[str]) -> int:
assert end is not None # Sanity check
return HeightMap(heights, start, end)
def djikstra(map: HeightMap) -> int:
def dijkstra(map: HeightMap) -> int:
# Priority queue of (distance, point)
queue = [(0, map.start)]
seen: set[Point] = set()
@ -81,7 +81,7 @@ def solve(input: list[str]) -> int:
)
for start in starts:
map.start = start
yield djikstra(map)
yield dijkstra(map)
map = to_height_map(input)
return min(hike_distances(map))

View file

@ -73,7 +73,7 @@ def solve(input: str) -> int:
assert end is not None # Sanity check
return ParsedMaze(start, end, blocks)
def djikstra(start: Point, end: Point, blocks: set[Point]) -> int:
def dijkstra(start: Point, end: Point, blocks: set[Point]) -> int:
def next_moves(
pos: Point,
dir: Direction,
@ -106,7 +106,7 @@ def solve(input: str) -> int:
assert False # Sanity check
start, end, blocks = parse(input.splitlines())
return djikstra(start, end, blocks)
return dijkstra(start, end, blocks)
def main() -> None:

View file

@ -27,7 +27,7 @@ def solve(input: str) -> int:
def parse(input: list[str]) -> list[Point]:
return [Point(*map(int, line.split(","))) for line in input]
def djikstra(start: Point, end: Point, blocks: set[Point]) -> int:
def dijkstra(start: Point, end: Point, blocks: set[Point]) -> int:
# Priority queue of (distance, point)
queue = [(0, start)]
seen: set[Point] = set()
@ -54,7 +54,7 @@ def solve(input: str) -> int:
assert False # Sanity check
coords = parse(input.splitlines())
return djikstra(Point(0, 0), DIMS, set(coords[:1024]))
return dijkstra(Point(0, 0), DIMS, set(coords[:1024]))
def main() -> None:

View file

@ -27,7 +27,7 @@ def solve(input: str) -> str:
def parse(input: list[str]) -> list[Point]:
return [Point(*map(int, line.split(","))) for line in input]
def djikstra(start: Point, end: Point, blocks: set[Point]) -> int | None:
def dijkstra(start: Point, end: Point, blocks: set[Point]) -> int | None:
# Priority queue of (distance, point)
queue = [(0, start)]
seen: set[Point] = set()
@ -58,7 +58,7 @@ def solve(input: str) -> str:
low, high = 0, len(blocks)
while low < high:
mid = low + (high - low) // 2
if djikstra(start, end, set(blocks[: mid + 1])) is None:
if dijkstra(start, end, set(blocks[: mid + 1])) is None:
high = mid
else:
low = mid + 1