diff options
author | Jack Sangdahl <[email protected]> | 2024-06-15 22:20:32 -0600 |
---|---|---|
committer | Jack Sangdahl <[email protected]> | 2024-06-15 22:20:32 -0600 |
commit | 8e313e2614c7a0fe5af924febdbacc650e33835e (patch) | |
tree | 63426b6942ceebe17708140c972a7d7451bd2f74 /24_2021.py | |
download | aoc-8e313e2614c7a0fe5af924febdbacc650e33835e.tar.gz aoc-8e313e2614c7a0fe5af924febdbacc650e33835e.zip |
intial
Diffstat (limited to '24_2021.py')
-rw-r--r-- | 24_2021.py | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/24_2021.py b/24_2021.py new file mode 100644 index 0000000..2322581 --- /dev/null +++ b/24_2021.py @@ -0,0 +1,25 @@ +with open("day24data.txt", "r") as file: + data = [ + x.strip("\n").strip().splitlines() for x in file.read().split("inp w\n")[1:] + ] + non_matching = [ + e + for e, x in enumerate(data[0]) + if not all(data[y][e] == x for y in range(len(data))) + ] + diffs = [ + [int(data[i][e].split()[-1]) for e in non_matching] for i in range(len(data)) + ] + q, mx, mn = [], [0] * 14, [0] * 14 + for a, x in enumerate(data): + if diffs[a][0] == 1: + q.append((a, diffs[a][2])) + else: + b, y = q.pop() + delta = y + diffs[a][1] + if not delta >= 0: + a, b, delta = b, a, -delta + mx[a], mx[b] = 9, 9 - delta + mn[b], mn[a] = 1, 1 + delta + print("".join([str(x) for x in mx])) + print("".join([str(x) for x in mn])) |