Skip to content

Commit ddbe8ab

Browse files
committed
2024: day 14. part 2. python. print xs tree
1 parent 9fbe592 commit ddbe8ab

File tree

1 file changed

+10
-11
lines changed

1 file changed

+10
-11
lines changed

src/2024/day14/2/solution.py

+10-11
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ def find_easter_egg_time(robots: list[tuple[tuple[int, int], tuple[int, int]]],
3838
max_duration: int = 1_000_000) -> int:
3939
max_neighbors = 0
4040
easter_egg_time = -1
41+
last_positions = None
4142

4243
for duration in range(max_duration):
4344
positions = simulate_robots(robots, duration, width, height)
@@ -54,21 +55,19 @@ def find_easter_egg_time(robots: list[tuple[tuple[int, int], tuple[int, int]]],
5455
if neighbors_count > max_neighbors:
5556
max_neighbors = neighbors_count
5657
easter_egg_time = duration
57-
58-
if duration % 1000 == 0 or neighbors_count > width * height * 0.3:
59-
matrix = [[0] * width for _ in range(height)]
60-
for x, y in positions:
61-
matrix[y][x] += 1
62-
63-
print(f"time: {duration}")
64-
print(f"neighbors: {neighbors_count}")
65-
for row in matrix:
66-
print(''.join(['#' if x else '.' for x in row]))
67-
print()
58+
last_positions = positions
6859

6960
if neighbors_count > width * height * 0.3:
7061
return duration
7162

63+
# print xs tree
64+
matrix = [[0] * width for _ in range(height)]
65+
for x, y in last_positions:
66+
matrix[y][x] += 1
67+
68+
for row in matrix:
69+
print(''.join(['#' if x else '.' for x in row]))
70+
print()
7271
return easter_egg_time
7372

7473

0 commit comments

Comments
 (0)