diff --git a/2024/14/06876.jpg b/2024/14/06876.jpg index 0e05f1d..93bcf17 100644 Binary files a/2024/14/06876.jpg and b/2024/14/06876.jpg differ diff --git a/2024/14/main.py b/2024/14/main.py index bb0d917..fba56d8 100644 --- a/2024/14/main.py +++ b/2024/14/main.py @@ -32,7 +32,7 @@ def get_robot_pos_after_time(area: dict, robot: tuple, seconds: int) -> tuple: return (finx, finy) -def get_quadrant(area: dict, position: tuple) -> int: +def get_quadrant_for_pos(area: dict, position: tuple) -> int: middle_x = area["width"] // 2 middle_y = area["height"] // 2 @@ -51,17 +51,17 @@ def get_quadrant(area: dict, position: tuple) -> int: return 4 -def assign_qadrants(area: dict, positions: dict) -> list: +def count_positions_in_quadrants(area: dict, positions: dict) -> list: quadrant_count = {} for pos, count in positions.items(): - quadrant = get_quadrant(area, pos) + quadrant = get_quadrant_for_pos(area, pos) if quadrant != 0: quadrant_count[quadrant] = quadrant_count.get(quadrant, 0) + count return quadrant_count -def draw_positions_in_area(area: dict, positions: dict, filename: str): +def draw_area(area: dict, positions: dict, filename: str): grid = [] for _ in range(area["height"]): row = [0] * area["width"] @@ -72,9 +72,9 @@ def draw_positions_in_area(area: dict, positions: dict, filename: str): grid[y][x] = 1 plt.figure() - plt.imshow(grid, cmap="gray", interpolation="nearest") + plt.imshow(grid, cmap="gray") plt.axis("off") - plt.savefig(f"{filename}.jpg", format="jpg", bbox_inches="tight", pad_inches=0) + plt.savefig(f"{filename}.jpg", bbox_inches="tight") plt.close() @@ -91,7 +91,7 @@ def main(): positions[pos] = positions.get(pos, 0) + 1 safety_factor = 1 - quadrant_count = assign_qadrants(area, positions) + quadrant_count = count_positions_in_quadrants(area, positions) for c in quadrant_count.values(): safety_factor *= c @@ -104,8 +104,8 @@ def main(): for robot in robots: pos = get_robot_pos_after_time(area, robot, i) positions[pos] = positions.get(pos, 0) + 1 - print(f"\rSaving image for position after {i} seconds", end="", flush=True) - draw_positions_in_area(area, positions, str("%05d" % i)) + print(f"\rSaving image for positions after {i} seconds", end="", flush=True) + draw_area(area, positions, str("%05d" % i)) if __name__ == "__main__":