mirror of
https://github.com/Crocmagnon/advent-of-code.git
synced 2024-12-30 17:51:53 +01:00
Solve day 10 part 1
This commit is contained in:
parent
3873358c14
commit
69932539a7
5 changed files with 352 additions and 21 deletions
57
2022/day10_cathode.py
Normal file
57
2022/day10_cathode.py
Normal file
|
@ -0,0 +1,57 @@
|
|||
def main(filename: str, expected_part_1: int = None, expected_part_2: int = None):
|
||||
print(f"\n+ Running on {filename}")
|
||||
with open(filename) as f:
|
||||
data = f.read().strip().split("\n")
|
||||
|
||||
data = parse_data(data)
|
||||
solution_part_1 = solve_part_1(data)
|
||||
|
||||
print(f"1. Found {solution_part_1}")
|
||||
if expected_part_1:
|
||||
assert expected_part_1 == solution_part_1
|
||||
|
||||
solution_part_2 = solve_part_2(data)
|
||||
print(f"2. Found {solution_part_2}")
|
||||
if expected_part_2:
|
||||
assert expected_part_2 == solution_part_2
|
||||
|
||||
|
||||
DataType = list[str]
|
||||
|
||||
|
||||
def parse_data(data: list[str]) -> DataType:
|
||||
return data
|
||||
|
||||
|
||||
def solve_part_1(data: DataType) -> int:
|
||||
total = 0
|
||||
register = 1
|
||||
clock = 0
|
||||
expected_cycles = [20, 60, 100, 140, 180, 220]
|
||||
for instruction in data:
|
||||
match instruction.split():
|
||||
case ["noop"]:
|
||||
clock += 1
|
||||
if clock in expected_cycles:
|
||||
print(f"{clock=}, {register=}")
|
||||
total += register * clock
|
||||
case ["addx", value]:
|
||||
clock += 1
|
||||
if clock in expected_cycles:
|
||||
print(f"{clock=}, {register=}")
|
||||
total += register * clock
|
||||
clock += 1
|
||||
if clock in expected_cycles:
|
||||
print(f"{clock=}, {register=}")
|
||||
total += register * clock
|
||||
register += int(value)
|
||||
return total
|
||||
|
||||
|
||||
def solve_part_2(data: DataType) -> int:
|
||||
return 0
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main("inputs/day10-test1", expected_part_1=13140)
|
||||
main("inputs/day10")
|
145
2022/inputs/day10
Normal file
145
2022/inputs/day10
Normal file
|
@ -0,0 +1,145 @@
|
|||
noop
|
||||
noop
|
||||
noop
|
||||
addx 3
|
||||
addx 7
|
||||
noop
|
||||
noop
|
||||
noop
|
||||
noop
|
||||
addx 6
|
||||
noop
|
||||
addx -1
|
||||
noop
|
||||
addx 5
|
||||
addx 1
|
||||
noop
|
||||
addx 4
|
||||
noop
|
||||
noop
|
||||
noop
|
||||
noop
|
||||
addx 6
|
||||
addx -1
|
||||
noop
|
||||
addx 3
|
||||
addx -13
|
||||
addx -22
|
||||
noop
|
||||
noop
|
||||
addx 3
|
||||
addx 2
|
||||
addx 11
|
||||
addx -4
|
||||
addx 11
|
||||
addx -10
|
||||
addx 2
|
||||
addx 5
|
||||
addx 2
|
||||
addx -2
|
||||
noop
|
||||
addx 7
|
||||
addx 3
|
||||
addx -2
|
||||
addx 2
|
||||
addx 5
|
||||
addx 2
|
||||
addx -2
|
||||
addx -8
|
||||
addx -27
|
||||
addx 5
|
||||
addx 2
|
||||
addx 21
|
||||
addx -21
|
||||
addx 3
|
||||
addx 5
|
||||
addx 2
|
||||
addx -3
|
||||
addx 4
|
||||
addx 3
|
||||
addx 1
|
||||
addx 5
|
||||
noop
|
||||
noop
|
||||
noop
|
||||
noop
|
||||
addx 3
|
||||
addx 1
|
||||
addx 6
|
||||
addx -31
|
||||
noop
|
||||
addx -4
|
||||
noop
|
||||
noop
|
||||
noop
|
||||
noop
|
||||
addx 3
|
||||
addx 7
|
||||
noop
|
||||
addx -1
|
||||
addx 1
|
||||
addx 5
|
||||
noop
|
||||
addx 1
|
||||
noop
|
||||
addx 2
|
||||
addx -8
|
||||
addx 15
|
||||
addx 3
|
||||
noop
|
||||
addx 2
|
||||
addx 5
|
||||
noop
|
||||
noop
|
||||
noop
|
||||
addx -28
|
||||
addx 11
|
||||
addx -20
|
||||
noop
|
||||
addx 7
|
||||
addx -2
|
||||
addx 7
|
||||
noop
|
||||
addx -2
|
||||
noop
|
||||
addx -6
|
||||
addx 11
|
||||
noop
|
||||
addx 3
|
||||
addx 2
|
||||
noop
|
||||
noop
|
||||
addx 7
|
||||
addx 3
|
||||
addx -2
|
||||
addx 2
|
||||
addx 5
|
||||
addx 2
|
||||
addx -16
|
||||
addx -10
|
||||
addx -11
|
||||
addx 27
|
||||
addx -20
|
||||
noop
|
||||
addx 2
|
||||
addx 3
|
||||
addx 5
|
||||
noop
|
||||
noop
|
||||
noop
|
||||
addx 3
|
||||
addx -2
|
||||
addx 2
|
||||
noop
|
||||
addx -14
|
||||
addx 21
|
||||
noop
|
||||
addx -6
|
||||
addx 12
|
||||
noop
|
||||
addx -21
|
||||
addx 24
|
||||
addx 2
|
||||
noop
|
||||
noop
|
||||
noop
|
146
2022/inputs/day10-test1
Normal file
146
2022/inputs/day10-test1
Normal file
|
@ -0,0 +1,146 @@
|
|||
addx 15
|
||||
addx -11
|
||||
addx 6
|
||||
addx -3
|
||||
addx 5
|
||||
addx -1
|
||||
addx -8
|
||||
addx 13
|
||||
addx 4
|
||||
noop
|
||||
addx -1
|
||||
addx 5
|
||||
addx -1
|
||||
addx 5
|
||||
addx -1
|
||||
addx 5
|
||||
addx -1
|
||||
addx 5
|
||||
addx -1
|
||||
addx -35
|
||||
addx 1
|
||||
addx 24
|
||||
addx -19
|
||||
addx 1
|
||||
addx 16
|
||||
addx -11
|
||||
noop
|
||||
noop
|
||||
addx 21
|
||||
addx -15
|
||||
noop
|
||||
noop
|
||||
addx -3
|
||||
addx 9
|
||||
addx 1
|
||||
addx -3
|
||||
addx 8
|
||||
addx 1
|
||||
addx 5
|
||||
noop
|
||||
noop
|
||||
noop
|
||||
noop
|
||||
noop
|
||||
addx -36
|
||||
noop
|
||||
addx 1
|
||||
addx 7
|
||||
noop
|
||||
noop
|
||||
noop
|
||||
addx 2
|
||||
addx 6
|
||||
noop
|
||||
noop
|
||||
noop
|
||||
noop
|
||||
noop
|
||||
addx 1
|
||||
noop
|
||||
noop
|
||||
addx 7
|
||||
addx 1
|
||||
noop
|
||||
addx -13
|
||||
addx 13
|
||||
addx 7
|
||||
noop
|
||||
addx 1
|
||||
addx -33
|
||||
noop
|
||||
noop
|
||||
noop
|
||||
addx 2
|
||||
noop
|
||||
noop
|
||||
noop
|
||||
addx 8
|
||||
noop
|
||||
addx -1
|
||||
addx 2
|
||||
addx 1
|
||||
noop
|
||||
addx 17
|
||||
addx -9
|
||||
addx 1
|
||||
addx 1
|
||||
addx -3
|
||||
addx 11
|
||||
noop
|
||||
noop
|
||||
addx 1
|
||||
noop
|
||||
addx 1
|
||||
noop
|
||||
noop
|
||||
addx -13
|
||||
addx -19
|
||||
addx 1
|
||||
addx 3
|
||||
addx 26
|
||||
addx -30
|
||||
addx 12
|
||||
addx -1
|
||||
addx 3
|
||||
addx 1
|
||||
noop
|
||||
noop
|
||||
noop
|
||||
addx -9
|
||||
addx 18
|
||||
addx 1
|
||||
addx 2
|
||||
noop
|
||||
noop
|
||||
addx 9
|
||||
noop
|
||||
noop
|
||||
noop
|
||||
addx -1
|
||||
addx 2
|
||||
addx -37
|
||||
addx 1
|
||||
addx 3
|
||||
noop
|
||||
addx 15
|
||||
addx -21
|
||||
addx 22
|
||||
addx -6
|
||||
addx 1
|
||||
noop
|
||||
addx 2
|
||||
addx 1
|
||||
noop
|
||||
addx -10
|
||||
noop
|
||||
noop
|
||||
addx 20
|
||||
addx 1
|
||||
addx 2
|
||||
addx 2
|
||||
addx -6
|
||||
addx -11
|
||||
noop
|
||||
noop
|
||||
noop
|
|
@ -1,24 +1,3 @@
|
|||
[tool.poetry]
|
||||
name = "advent-of-code"
|
||||
version = "0.1.0"
|
||||
description = ""
|
||||
authors = ["Gabriel Augendre <gabriel@augendre.info>"]
|
||||
license = "Unlicense"
|
||||
|
||||
[tool.poetry.dependencies]
|
||||
python = "^3.10"
|
||||
networkx = ">=2.5"
|
||||
pdbpp = ">=0.10.2"
|
||||
|
||||
[tool.poetry.dev-dependencies]
|
||||
pre-commit = ">=2.9.2"
|
||||
pytest = ">=6.1.2"
|
||||
|
||||
[build-system]
|
||||
requires = ["poetry-core>=1.0.0"]
|
||||
build-backend = "poetry.core.masonry.api"
|
||||
|
||||
|
||||
###############################################################################
|
||||
# flake8 / flakeheaven
|
||||
###############################################################################
|
||||
|
|
4
requirements.txt
Normal file
4
requirements.txt
Normal file
|
@ -0,0 +1,4 @@
|
|||
networkx>=2.5
|
||||
|
||||
pre-commit
|
||||
pytest
|
Loading…
Reference in a new issue