mirror of
https://github.com/Crocmagnon/advent-of-code.git
synced 2024-11-21 22:18:12 +01:00
Solve day 10 part 2
This commit is contained in:
parent
69932539a7
commit
aa723d8a6f
1 changed files with 31 additions and 3 deletions
|
@ -48,10 +48,38 @@ def solve_part_1(data: DataType) -> int:
|
|||
return total
|
||||
|
||||
|
||||
def solve_part_2(data: DataType) -> int:
|
||||
return 0
|
||||
def solve_part_2(data: DataType) -> None:
|
||||
register = 1
|
||||
clock = 0
|
||||
for instruction in data:
|
||||
match instruction.split():
|
||||
case ["noop"]:
|
||||
clock += 1
|
||||
end_of_cycle(clock, register)
|
||||
case ["addx", value]:
|
||||
clock += 1
|
||||
end_of_cycle(clock, register)
|
||||
clock += 1
|
||||
end_of_cycle(clock, register)
|
||||
register += int(value)
|
||||
|
||||
|
||||
def end_of_cycle(clock: int, register: int) -> None:
|
||||
if (clock % 40 - 1) in sprite_indices(register):
|
||||
char = "#"
|
||||
else:
|
||||
char = "."
|
||||
if clock % 40 == 0:
|
||||
end = "\n"
|
||||
else:
|
||||
end = ""
|
||||
print(char, end=end)
|
||||
|
||||
|
||||
def sprite_indices(register: int) -> tuple[int, int, int]:
|
||||
return register - 1, register, register + 1
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main("inputs/day10-test1", expected_part_1=13140)
|
||||
main("inputs/day10")
|
||||
main("inputs/day10", expected_part_1=12560)
|
||||
|
|
Loading…
Reference in a new issue