Compare commits
3 commits
785205eac7
...
b4d9ecf0a5
| Author | SHA1 | Date | |
|---|---|---|---|
| b4d9ecf0a5 | |||
| 7dee19ff44 | |||
| b8c422ab31 |
12 changed files with 59 additions and 20 deletions
9
2016/d25/ex2/ex2.py
Executable file
9
2016/d25/ex2/ex2.py
Executable file
|
|
@ -0,0 +1,9 @@
|
||||||
|
#!/usr/bin/env python
|
||||||
|
|
||||||
|
|
||||||
|
def main() -> None:
|
||||||
|
print("There is no part two...")
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main()
|
||||||
30
2016/d25/ex2/input
Normal file
30
2016/d25/ex2/input
Normal file
|
|
@ -0,0 +1,30 @@
|
||||||
|
cpy a d
|
||||||
|
cpy 15 c
|
||||||
|
cpy 170 b
|
||||||
|
inc d
|
||||||
|
dec b
|
||||||
|
jnz b -2
|
||||||
|
dec c
|
||||||
|
jnz c -5
|
||||||
|
cpy d a
|
||||||
|
jnz 0 0
|
||||||
|
cpy a b
|
||||||
|
cpy 0 a
|
||||||
|
cpy 2 c
|
||||||
|
jnz b 2
|
||||||
|
jnz 1 6
|
||||||
|
dec b
|
||||||
|
dec c
|
||||||
|
jnz c -4
|
||||||
|
inc a
|
||||||
|
jnz 1 -7
|
||||||
|
cpy 2 b
|
||||||
|
jnz c 2
|
||||||
|
jnz 1 4
|
||||||
|
dec b
|
||||||
|
dec c
|
||||||
|
jnz 1 -4
|
||||||
|
jnz 0 0
|
||||||
|
out b
|
||||||
|
jnz a -19
|
||||||
|
jnz 1 -21
|
||||||
|
|
@ -92,7 +92,7 @@ def solve(input: str) -> int:
|
||||||
for gear in (Gear.TORCH, Gear.NEITHER):
|
for gear in (Gear.TORCH, Gear.NEITHER):
|
||||||
yield 1 + (7 if gear != explorer.gear else 0), Explorer(n, gear)
|
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)
|
# Priority queue of (distance, point)
|
||||||
queue = [(0, start)]
|
queue = [(0, start)]
|
||||||
seen: set[Explorer] = set()
|
seen: set[Explorer] = set()
|
||||||
|
|
@ -116,7 +116,7 @@ def solve(input: str) -> int:
|
||||||
cave = Cave(depth, target)
|
cave = Cave(depth, target)
|
||||||
start = Explorer(Point(0, 0), Gear.TORCH)
|
start = Explorer(Point(0, 0), Gear.TORCH)
|
||||||
end = Explorer(target, Gear.TORCH)
|
end = Explorer(target, Gear.TORCH)
|
||||||
return djikstra(start, end, cave)
|
return dijkstra(start, end, cave)
|
||||||
|
|
||||||
|
|
||||||
def main() -> None:
|
def main() -> None:
|
||||||
|
|
|
||||||
|
|
@ -73,7 +73,7 @@ def solve(input: str) -> int:
|
||||||
graph = to_graph(paths, post_process_gates(letters, paths))
|
graph = to_graph(paths, post_process_gates(letters, paths))
|
||||||
return graph, next(iter(gates["AA"])), next(iter(gates["ZZ"]))
|
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)
|
# Priority queue of (distance, point)
|
||||||
queue = [(0, start)]
|
queue = [(0, start)]
|
||||||
seen: set[Point] = set()
|
seen: set[Point] = set()
|
||||||
|
|
@ -94,7 +94,7 @@ def solve(input: str) -> int:
|
||||||
assert False # Sanity check
|
assert False # Sanity check
|
||||||
|
|
||||||
graph, start, end = parse(input.splitlines())
|
graph, start, end = parse(input.splitlines())
|
||||||
return djikstra(start, end, graph)
|
return dijkstra(start, end, graph)
|
||||||
|
|
||||||
|
|
||||||
def main() -> None:
|
def main() -> None:
|
||||||
|
|
|
||||||
|
|
@ -87,7 +87,7 @@ def solve(input: str) -> int:
|
||||||
graph = to_graph(paths, post_process_gates(letters, paths))
|
graph = to_graph(paths, post_process_gates(letters, paths))
|
||||||
return graph, next(iter(gates["AA"])), next(iter(gates["ZZ"]))
|
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)
|
# Priority queue of (distance, point, level)
|
||||||
queue = [(0, start, 0)]
|
queue = [(0, start, 0)]
|
||||||
seen: set[tuple[Point, int]] = set()
|
seen: set[tuple[Point, int]] = set()
|
||||||
|
|
@ -112,7 +112,7 @@ def solve(input: str) -> int:
|
||||||
assert False # Sanity check
|
assert False # Sanity check
|
||||||
|
|
||||||
graph, start, end = parse(input.splitlines())
|
graph, start, end = parse(input.splitlines())
|
||||||
return djikstra(start, end, graph)
|
return dijkstra(start, end, graph)
|
||||||
|
|
||||||
|
|
||||||
def main() -> None:
|
def main() -> None:
|
||||||
|
|
|
||||||
|
|
@ -22,7 +22,7 @@ def solve(input: List[str]) -> int:
|
||||||
continue
|
continue
|
||||||
yield Point(x, y)
|
yield Point(x, y)
|
||||||
|
|
||||||
def djikstra(start: Point, end: Point) -> int:
|
def dijkstra(start: Point, end: Point) -> int:
|
||||||
# Priority queue of (distance, point)
|
# Priority queue of (distance, point)
|
||||||
queue = [(0, start)]
|
queue = [(0, start)]
|
||||||
seen: Set[Point] = set()
|
seen: Set[Point] = set()
|
||||||
|
|
@ -42,7 +42,7 @@ def solve(input: List[str]) -> int:
|
||||||
|
|
||||||
assert False # Sanity check
|
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:
|
def main() -> None:
|
||||||
|
|
|
||||||
|
|
@ -43,7 +43,7 @@ def solve(input: List[str]) -> int:
|
||||||
continue
|
continue
|
||||||
yield Point(x, y)
|
yield Point(x, y)
|
||||||
|
|
||||||
def djikstra(start: Point, end: Point) -> int:
|
def dijkstra(start: Point, end: Point) -> int:
|
||||||
# Priority queue of (distance, point)
|
# Priority queue of (distance, point)
|
||||||
queue = [(0, start)]
|
queue = [(0, start)]
|
||||||
seen: Set[Point] = set()
|
seen: Set[Point] = set()
|
||||||
|
|
@ -63,7 +63,7 @@ def solve(input: List[str]) -> int:
|
||||||
|
|
||||||
assert False # Sanity check
|
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:
|
def main() -> None:
|
||||||
|
|
|
||||||
|
|
@ -51,7 +51,7 @@ def solve(input: list[str]) -> int:
|
||||||
assert end is not None # Sanity check
|
assert end is not None # Sanity check
|
||||||
return HeightMap(heights, start, end)
|
return HeightMap(heights, start, end)
|
||||||
|
|
||||||
def djikstra(map: HeightMap) -> int:
|
def dijkstra(map: HeightMap) -> int:
|
||||||
# Priority queue of (distance, point)
|
# Priority queue of (distance, point)
|
||||||
queue = [(0, map.start)]
|
queue = [(0, map.start)]
|
||||||
seen: set[Point] = set()
|
seen: set[Point] = set()
|
||||||
|
|
@ -72,7 +72,7 @@ def solve(input: list[str]) -> int:
|
||||||
assert False # Sanity check
|
assert False # Sanity check
|
||||||
|
|
||||||
map = to_height_map(input)
|
map = to_height_map(input)
|
||||||
return djikstra(map)
|
return dijkstra(map)
|
||||||
|
|
||||||
|
|
||||||
def main() -> None:
|
def main() -> None:
|
||||||
|
|
|
||||||
|
|
@ -51,7 +51,7 @@ def solve(input: list[str]) -> int:
|
||||||
assert end is not None # Sanity check
|
assert end is not None # Sanity check
|
||||||
return HeightMap(heights, start, end)
|
return HeightMap(heights, start, end)
|
||||||
|
|
||||||
def djikstra(map: HeightMap) -> int:
|
def dijkstra(map: HeightMap) -> int:
|
||||||
# Priority queue of (distance, point)
|
# Priority queue of (distance, point)
|
||||||
queue = [(0, map.start)]
|
queue = [(0, map.start)]
|
||||||
seen: set[Point] = set()
|
seen: set[Point] = set()
|
||||||
|
|
@ -81,7 +81,7 @@ def solve(input: list[str]) -> int:
|
||||||
)
|
)
|
||||||
for start in starts:
|
for start in starts:
|
||||||
map.start = start
|
map.start = start
|
||||||
yield djikstra(map)
|
yield dijkstra(map)
|
||||||
|
|
||||||
map = to_height_map(input)
|
map = to_height_map(input)
|
||||||
return min(hike_distances(map))
|
return min(hike_distances(map))
|
||||||
|
|
|
||||||
|
|
@ -73,7 +73,7 @@ def solve(input: str) -> int:
|
||||||
assert end is not None # Sanity check
|
assert end is not None # Sanity check
|
||||||
return ParsedMaze(start, end, blocks)
|
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(
|
def next_moves(
|
||||||
pos: Point,
|
pos: Point,
|
||||||
dir: Direction,
|
dir: Direction,
|
||||||
|
|
@ -106,7 +106,7 @@ def solve(input: str) -> int:
|
||||||
assert False # Sanity check
|
assert False # Sanity check
|
||||||
|
|
||||||
start, end, blocks = parse(input.splitlines())
|
start, end, blocks = parse(input.splitlines())
|
||||||
return djikstra(start, end, blocks)
|
return dijkstra(start, end, blocks)
|
||||||
|
|
||||||
|
|
||||||
def main() -> None:
|
def main() -> None:
|
||||||
|
|
|
||||||
|
|
@ -27,7 +27,7 @@ def solve(input: str) -> int:
|
||||||
def parse(input: list[str]) -> list[Point]:
|
def parse(input: list[str]) -> list[Point]:
|
||||||
return [Point(*map(int, line.split(","))) for line in input]
|
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)
|
# Priority queue of (distance, point)
|
||||||
queue = [(0, start)]
|
queue = [(0, start)]
|
||||||
seen: set[Point] = set()
|
seen: set[Point] = set()
|
||||||
|
|
@ -54,7 +54,7 @@ def solve(input: str) -> int:
|
||||||
assert False # Sanity check
|
assert False # Sanity check
|
||||||
|
|
||||||
coords = parse(input.splitlines())
|
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:
|
def main() -> None:
|
||||||
|
|
|
||||||
|
|
@ -27,7 +27,7 @@ def solve(input: str) -> str:
|
||||||
def parse(input: list[str]) -> list[Point]:
|
def parse(input: list[str]) -> list[Point]:
|
||||||
return [Point(*map(int, line.split(","))) for line in input]
|
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)
|
# Priority queue of (distance, point)
|
||||||
queue = [(0, start)]
|
queue = [(0, start)]
|
||||||
seen: set[Point] = set()
|
seen: set[Point] = set()
|
||||||
|
|
@ -58,7 +58,7 @@ def solve(input: str) -> str:
|
||||||
low, high = 0, len(blocks)
|
low, high = 0, len(blocks)
|
||||||
while low < high:
|
while low < high:
|
||||||
mid = low + (high - low) // 2
|
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
|
high = mid
|
||||||
else:
|
else:
|
||||||
low = mid + 1
|
low = mid + 1
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue