-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
190 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |