Solve 2022 dat 10 pt 1-2
Not pretty, but it works :)
This commit is contained in:
parent
e7ddb92024
commit
abc28306b3
1 changed files with 50 additions and 0 deletions
50
2022-python/output/day_10.py
Normal file
50
2022-python/output/day_10.py
Normal file
|
|
@ -0,0 +1,50 @@
|
||||||
|
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 = None
|
||||||
|
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"
|
||||||
Loading…
Add table
Reference in a new issue