diff options
author | Marvin Borner | 2023-12-05 14:36:29 +0100 |
---|---|---|
committer | Marvin Borner | 2023-12-05 14:36:29 +0100 |
commit | 9d262edc6bc4df3a5f6af8b9e8089e9eb1c82684 (patch) | |
tree | e578ee47ebdf7df3c03a785a555ab3ac9c2e8d33 | |
parent | 8785821aec6ab28de2bf5e802284795e2405f4d6 (diff) |
Initial (AAAH)
-rw-r--r-- | 2023/05/solve.py | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/2023/05/solve.py b/2023/05/solve.py new file mode 100644 index 0000000..965a81e --- /dev/null +++ b/2023/05/solve.py @@ -0,0 +1,39 @@ +L = open("input").read().strip().split("\n\n") + + +def part1(): + seeds = [] + mp = [] + + allI = [] + + for b in L: + ls = b.split("\n") + if ls[0].startswith("seeds:"): + seeds = [int(n) for n in ls[0].split(" ")[1:]] + continue + + mp.append({}) + curr = mp[len(mp) - 1] + for m in ls[1:]: + ms = [int(n) for n in m.split(" ")] + for off in range(ms[2]): + # curr[ms[1] + off] = ms[0] + off + curr[ms[0] + off] = ms[1] + off + allI += list(range(ms[0], ms[0] + ms[2])) + + # for i in range(len(mp) - 1, -1, -1): + mn = float("infinity") + res = 0 + for loc in allI: + curr = mp[-1].get(loc, loc) + for i in range(len(mp) - 2, -1, -1): + curr = mp[i].get(curr, curr) + print(loc, curr) + if curr in seeds and loc < mn: + mn = curr + res = loc + print(res) + + +part1() |