Solve 2022 dat 10 pt 1-2

Not pretty, but it works :)
This commit is contained in:
Anders Englöf Ytterström 2025-11-28 00:24:56 +01:00
parent e7ddb92024
commit f610c96257

View file

@ -0,0 +1,49 @@
from output import sints
def solve(data):
x = 1
P = data.splitlines()
p1 = 0
c = 0
p = 0
running = True
busy = False
pixels = []
while running:
if not p < len(P) and not busy:
running = False
continue
line = P[min([p, len(P) - 1])]
if (c + 21) % 40 == 0:
p1 += (c + 1) * x
if c % 40 == 0:
pixels.append("\n")
pixels.append("" if (x - 1) <= (c % 40) <= (x + 1) else " ")
if busy:
busy = False
x += int(sints(line)[0])
p += 1
c += 1
continue
if line.startswith("noop"):
p += 1
c += 1
continue
busy = True
c += 1
p2 = "".join(pixels)
return p1, p2
if __name__ == "__main__":
with open("./input/10.txt", "r") as f:
inp = f.read().strip()
p1, p2 = solve(inp)
print(p1)
print(p2)
assert p1 == 11820
# assert p2 == "EPJBRKAH"