summaryrefslogtreecommitdiff
path: root/2024/09/python/main.py
diff options
context:
space:
mode:
authormhsn <mail@mhsn.net>2025-09-12 20:20:58 +0100
committermhsn <mail@mhsn.net>2025-09-12 20:36:09 +0100
commit6b733982f9f240c1c97f1fa705bfbe4cd93c640e (patch)
treedad623203c8bb40f372e0ea14479c2f564efda79 /2024/09/python/main.py
parent9299c4ef655b88eb8b571864c939c78b27f77723 (diff)
downloadaoc-6b733982f9f240c1c97f1fa705bfbe4cd93c640e.tar.gz
aoc-6b733982f9f240c1c97f1fa705bfbe4cd93c640e.zip
simplify python file structure
Diffstat (limited to '2024/09/python/main.py')
-rw-r--r--2024/09/python/main.py60
1 files changed, 0 insertions, 60 deletions
diff --git a/2024/09/python/main.py b/2024/09/python/main.py
deleted file mode 100644
index d435163..0000000
--- a/2024/09/python/main.py
+++ /dev/null
@@ -1,60 +0,0 @@
-from fileinput import input
-
-disk = list(input())[0].strip()
-
-id_ = -1
-blocks = []
-tail = 0
-file = True
-for c in disk:
- blocks.append([tail, tail + int(c), (id_ := id_ + 1) if file else -1])
- tail += int(c)
- file = not file
-
-
-def expand(bs):
- return [x for a, b, x in sorted(bs) for _ in range(b - a)]
-
-
-def debug(bs):
- print("".join(str(b) if b != -1 else "." for b in expand(bs)))
-
-
-# Silver
-expanded = expand(blocks)
-tail = len(expanded) - 1
-fill = expanded.index(-1)
-while fill < tail:
- expanded[fill] = expanded[tail]
- expanded[tail] = -1
- while expanded[tail] == -1:
- tail -= 1
- while expanded[fill] != -1:
- fill += 1
-silver = sum(idx * n for idx, n in enumerate(expanded) if n != -1)
-
-
-# Gold
-for move in blocks[::-1]:
- print(move)
- ma, mb, mx = move
- if mx == -1:
- continue
- mlen = mb - ma
- for tidx, to in enumerate(blocks):
- ta, tb, tx = to
- if ta >= ma:
- break
- if tx != -1:
- continue
- if (tlen := tb - ta) < mlen:
- continue
- move[2] = -1
- to[2] = mx
- to[1] = ta + mlen
- blocks.insert(tidx + 1, [ta + mlen, tb, -1])
- break
-gold = sum(idx * n for idx, n in enumerate(expand(blocks)) if n != -1)
-
-print("silver:", silver)
-print("gold:", gold)