Skip to content

Commit

Permalink
[2022][day 10] adding solution
Browse files Browse the repository at this point in the history
  • Loading branch information
IAjimi committed Dec 11, 2022
1 parent 0a4b080 commit 443a67c
Show file tree
Hide file tree
Showing 3 changed files with 190 additions and 0 deletions.
48 changes: 48 additions & 0 deletions 2022/AOC10.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
from typing import List

from _utils import read_input, timer, Solution


def process_input(filename: str) -> List[str]:
_input = read_input(filename)
return _input


def process_instructions(_input: List[str]) -> List[int]:
X = [1]

for line in _input:
X.append(X[-1])

if line.startswith("addx"):
_, val = line.split(" ")
X.append(X[-1] + int(val))

return X


def produce_image(X: List[int]) -> str:
image = ""
for i in range(0, 240, 40):
row = [
"#" if x - 1 <= cycle <= x + 1 else "."
for cycle, x in enumerate(X[i : i + 40])
]
image += " ".join(row)
image += "\n"
return image


@timer
def main(filename: str) -> Solution:
_input = process_input(filename)
X = process_instructions(_input)
part_1_solution = sum([X[i - 1] * i for i in range(20, 220 + 1, 40)])
part_2_solution = produce_image(X)
return part_1_solution, part_2_solution


if __name__ == "__main__":
part_1_solution, part_2_solution = main("aoc10.txt")
print(f"PART 1: {part_1_solution}") # 12880
print(f"PART 2: \n {part_2_solution}") # FCJAPJRE
2 changes: 2 additions & 0 deletions 2022/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,5 @@ This repository contains Python solutions to the 2022 edition of [Advent of Code
| [6](https://adventofcode.com/2022/day/6) | **Tuning Trouble** | [:star::star:](https://github.com/IAjimi/AdventOfCode/blob/master/2022/AOC06.py) |
| [7](https://adventofcode.com/2022/day/7) | **No Space Left On Device** | [:star::star:](https://github.com/IAjimi/AdventOfCode/blob/master/2022/AOC07.py) |
| [8](https://adventofcode.com/2022/day/8) | **Treetop Tree House** | [:star::star:](https://github.com/IAjimi/AdventOfCode/blob/master/2022/AOC08.py) |
| [9](https://adventofcode.com/2022/day/9) | **Rope Bridge** | [:star::star:](https://github.com/IAjimi/AdventOfCode/blob/master/2022/AOC09.py) |
| [10](https://adventofcode.com/2022/day/10) | **Cathode-Ray Tube** | [:star::star:](https://github.com/IAjimi/AdventOfCode/blob/master/2022/AOC10.py) |
140 changes: 140 additions & 0 deletions 2022/aoc10.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
addx 2
addx 15
addx -11
addx 6
noop
noop
noop
addx -1
addx 5
addx -1
addx 5
noop
noop
noop
noop
noop
addx 7
addx -1
addx 3
addx 1
addx 5
addx 1
noop
addx -38
noop
addx 1
addx 6
addx 3
noop
addx -8
noop
addx 13
addx 2
addx 3
addx -2
addx 2
noop
addx 3
addx 9
addx -2
addx 2
addx -10
addx 11
addx 2
addx -14
addx -21
addx 2
noop
addx 5
addx 29
addx -2
noop
addx -19
noop
addx 2
addx 11
addx -10
addx 2
addx 5
addx -9
noop
addx 14
addx 2
addx 3
addx -2
addx 3
addx 1
noop
addx -37
noop
addx 13
addx -8
noop
noop
noop
noop
addx 13
addx -5
addx 3
addx 3
addx 3
noop
noop
noop
noop
noop
noop
noop
addx 6
addx 3
addx 1
addx 5
addx -15
addx 5
addx -27
addx 30
addx -23
addx 33
addx -32
addx 2
addx 5
addx 2
addx -16
addx 17
addx 2
addx -10
addx 17
addx 10
addx -9
addx 2
addx 2
addx 5
addx -29
addx -8
noop
noop
noop
addx 19
addx -11
addx -1
addx 6
noop
noop
addx -1
addx 3
noop
addx 3
addx 2
addx -3
addx 11
addx -1
addx 5
addx -2
addx 5
addx 2
noop
noop
addx 1
noop
noop

0 comments on commit 443a67c

Please sign in to comment.