From fde8a0968fe913ff02529de792b8ed7785389131 Mon Sep 17 00:00:00 2001 From: Sebastian Mark Date: Sat, 14 Dec 2024 15:32:32 +0100 Subject: [PATCH] add 2024/day14.2 --- 2024/14/06876.jpg | Bin 0 -> 12934 bytes 2024/14/main.py | 39 ++++++++++++++++++++++++++++++++------- 2 files changed, 32 insertions(+), 7 deletions(-) create mode 100644 2024/14/06876.jpg diff --git a/2024/14/06876.jpg b/2024/14/06876.jpg new file mode 100644 index 0000000000000000000000000000000000000000..0e05f1da2f7d2d0fc1fe4f1ef4b027b670b54fe8 GIT binary patch literal 12934 zcmd6N2{@GN|Mz1{WlNUq6h&zzOAM0~$&sXRtck2KA^S2#C}E1EQfQH6OM{VZlC@+j z>sZE^?8c03EMsQgTb-pk=XZYR{a^pPoP^$_JI!CSlpIVFNc8w+Ii9h|*SxtxEsbKg_of z|9TcL7B@DQZ4fIz3mZQRvj&oeAQld=+O-A$_QS%;#?G;hbNz;mT;PVHO%N*!8yhP- z8wUqFJGeU(d=Ihnb8OyvKxdtRi9P2wFF~cNw;!*UJyK95bh?cqr+nT!e8WcJEh3^~ z+jqz-?A&!wMO97xkcRHjV|x0>4NjPzIcsKa@vEhS;{_*Y7gsl*%f5d80f9jg*CL~$ zuiuDCNW7DDH~HTE2Tz_p%XpsoBJ1UAbYW33rsPfOyXuo)6{aN2tbY*V_rUhv56#|2dzWR*`-gwA`nZ4{O}NZ3BJX4+TF{+(gr|0B!(Fzipe za1b{e3wU{K{16;kX2d9@^Y929Z4c4U(Rntm%7k1h)BKZ#7mRw(6bxTyyJEZ}8{ggM z`XH_;@=KUaM@~NX`x42#XHlXO5}Sg~#tB%phaAe$$#zwfcCL)@Pu^P_T6QOkaFsJ$ ze_J*lZ|xQo*F^u4dZD8||6ofYPjk&(bqVf-pi>+{3Qw+R@-11c)UPU{mUI|R4)ps> zNXrlYh*8!wS%w%OPS3ASqMpP+3ScNcqnu5S+*fq}$xKwHf9Cj5|ARvwXV9Yldj$#7 zaT%zS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int: disable=missing-module-docstring,missing-function-docstring,consider-using-f-string,no-else-return import re +import matplotlib.pyplot as plt def readinput(): @@ -25,13 +26,10 @@ def readinput(): def get_robot_pos_after_time(area: dict, robot: tuple, seconds: int) -> tuple: - for _ in range(seconds): - nxtx = (robot["pos"][0] + robot["move"][0]) % area["width"] - nxty = (robot["pos"][1] + robot["move"][1]) % area["height"] + finx = (robot["pos"][0] + robot["move"][0] * seconds) % area["width"] + finy = (robot["pos"][1] + robot["move"][1] * seconds) % area["height"] - robot["pos"] = nxtx, nxty - - return robot["pos"] + return (finx, finy) def get_quadrant(area: dict, position: tuple) -> int: @@ -63,13 +61,30 @@ def assign_qadrants(area: dict, positions: dict) -> list: return quadrant_count +def draw_positions_in_area(area: dict, positions: dict, filename: str): + grid = [] + for _ in range(area["height"]): + row = [0] * area["width"] + grid.append(row) + + for pos in positions.keys(): + x, y = pos + grid[y][x] = 1 + + plt.figure() + plt.imshow(grid, cmap="gray", interpolation="nearest") + plt.axis("off") + plt.savefig(f"{filename}.jpg", format="jpg", bbox_inches="tight", pad_inches=0) + plt.close() + + def main(): robots = readinput() area = {"width": 101, "height": 103} - seconds = 100 # part 1 + seconds = 100 positions = {} for robot in robots: pos = get_robot_pos_after_time(area, robot, seconds) @@ -82,6 +97,16 @@ def main(): print("Safety factor: %d" % safety_factor) + # part 2 + seconds = 10_000 + for i in range(seconds): + positions = {} + 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)) + if __name__ == "__main__": main()