From 656db880abe9987d1008e5a76873c2e19d4615b4 Mon Sep 17 00:00:00 2001 From: Bruno BELANYI Date: Tue, 20 May 2025 02:02:04 +0100 Subject: [PATCH 1/3] 2016: d25: ex2: add input --- 2016/d25/ex2/input | 62 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100644 2016/d25/ex2/input diff --git a/2016/d25/ex2/input b/2016/d25/ex2/input new file mode 100644 index 0000000..199164f --- /dev/null +++ b/2016/d25/ex2/input @@ -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. From ef539ad5cb4a475688ce921a2f49463a2ff6719a Mon Sep 17 00:00:00 2001 From: Bruno BELANYI Date: Tue, 20 May 2025 02:02:09 +0100 Subject: [PATCH 2/3] 2016: d25: ex2: add solution --- 2016/d25/ex2/ex2.py | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100755 2016/d25/ex2/ex2.py diff --git a/2016/d25/ex2/ex2.py b/2016/d25/ex2/ex2.py new file mode 100755 index 0000000..918e0ec --- /dev/null +++ b/2016/d25/ex2/ex2.py @@ -0,0 +1,9 @@ +#!/usr/bin/env python + + +def main() -> None: + print("There is no part two...") + + +if __name__ == "__main__": + main() From 785205eac774ecfe5ca3fbf09fd43d6e30afbdf2 Mon Sep 17 00:00:00 2001 From: Bruno BELANYI Date: Tue, 20 May 2025 02:03:36 +0100 Subject: [PATCH 3/3] treewide: fix 'dijkstra' typo The downside of copy-pasting snippets from previous solutions :'). --- 2018/d22/ex2/ex2.py | 4 ++-- 2019/d20/ex1/ex1.py | 4 ++-- 2019/d20/ex2/ex2.py | 4 ++-- 2021/d15/ex1/ex1.py | 4 ++-- 2021/d15/ex2/ex2.py | 4 ++-- 2022/d12/ex1/ex1.py | 4 ++-- 2022/d12/ex2/ex2.py | 4 ++-- 2024/d16/ex1/ex1.py | 4 ++-- 2024/d18/ex1/ex1.py | 4 ++-- 2024/d18/ex2/ex2.py | 4 ++-- 10 files changed, 20 insertions(+), 20 deletions(-) diff --git a/2018/d22/ex2/ex2.py b/2018/d22/ex2/ex2.py index d27f3a3..fca477f 100755 --- a/2018/d22/ex2/ex2.py +++ b/2018/d22/ex2/ex2.py @@ -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: diff --git a/2019/d20/ex1/ex1.py b/2019/d20/ex1/ex1.py index fd37c03..b43729e 100755 --- a/2019/d20/ex1/ex1.py +++ b/2019/d20/ex1/ex1.py @@ -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: diff --git a/2019/d20/ex2/ex2.py b/2019/d20/ex2/ex2.py index 79cc181..cb72455 100755 --- a/2019/d20/ex2/ex2.py +++ b/2019/d20/ex2/ex2.py @@ -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: diff --git a/2021/d15/ex1/ex1.py b/2021/d15/ex1/ex1.py index 4399aba..022da89 100755 --- a/2021/d15/ex1/ex1.py +++ b/2021/d15/ex1/ex1.py @@ -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: diff --git a/2021/d15/ex2/ex2.py b/2021/d15/ex2/ex2.py index c2bbd30..a51dd3f 100755 --- a/2021/d15/ex2/ex2.py +++ b/2021/d15/ex2/ex2.py @@ -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: diff --git a/2022/d12/ex1/ex1.py b/2022/d12/ex1/ex1.py index 3e78cfc..0a423e5 100755 --- a/2022/d12/ex1/ex1.py +++ b/2022/d12/ex1/ex1.py @@ -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: diff --git a/2022/d12/ex2/ex2.py b/2022/d12/ex2/ex2.py index 0a713b3..b937741 100755 --- a/2022/d12/ex2/ex2.py +++ b/2022/d12/ex2/ex2.py @@ -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)) diff --git a/2024/d16/ex1/ex1.py b/2024/d16/ex1/ex1.py index 4eb3c46..9055f40 100755 --- a/2024/d16/ex1/ex1.py +++ b/2024/d16/ex1/ex1.py @@ -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: diff --git a/2024/d18/ex1/ex1.py b/2024/d18/ex1/ex1.py index be33528..650291e 100755 --- a/2024/d18/ex1/ex1.py +++ b/2024/d18/ex1/ex1.py @@ -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: diff --git a/2024/d18/ex2/ex2.py b/2024/d18/ex2/ex2.py index 046324b..1f46759 100755 --- a/2024/d18/ex2/ex2.py +++ b/2024/d18/ex2/ex2.py @@ -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