2022/day10/common.py
2024-12-02 14:57:20 +01:00

20 lines
550 B
Python

from typing import TypeAlias
from enum import Enum
class Operation(Enum):
NOOP = 'noop'
ADDX = 'addx'
Instruction: TypeAlias = tuple[Operation, int|None]
def parse(filename: str) -> list[Instruction]:
instructions = []
with open(filename) as f:
while line:=f.readline().strip("\n"):
oper = line.split()
if len(oper) > 1:
instructions.append((Operation(oper[0]), int(oper[1])))
else:
instructions.append((Operation(oper[0]), None))
return instructions