Exemplo n.º 1
0
# https://adventofcode.com/2019/day/21

from intcode import IntcodeComputer

with open("../../input/2019-21-input.txt") as file:
    code = [int(i) for i in file.read().split(",")]
droid = IntcodeComputer(code, silent=True, feedback_mode=True, ascii_mode=True)

# Catch the output and print only the final numbers.

# part 1
droid_output = droid.run_ascii()
# print(droid_output)  # Droid asks for input.
# Jump if there is a hole at A or B or C but only if there is ground at D.
springscript_1 = """\
NOT B J
NOT C T
OR T J
NOT A T
OR T J
AND D J
WALK
"""
droid_output = droid.run_ascii(springscript_1)
# print(droid_output)
print(droid_output.splitlines()[-1])  # 19362259

# part 2
droid.reset()
droid_output = droid.run_ascii()
# print(droid_output)
Exemplo n.º 2
0
# https://adventofcode.com/2019/day/17

import math

from intcode import IntcodeComputer

with open("../../input/2019-17-input.txt") as file:
    code = [int(i) for i in file.read().split(",")]

droid = IntcodeComputer(code, True, True, ascii_mode=True)
scaffold = droid.run_ascii()
# print(scaffold)
scaffold = scaffold.strip().splitlines()

# part 1
intersections = []
width = len(scaffold[0])
height = len(scaffold)
for x in range(1, width - 1):
    for y in range(1, height - 1):
        if (scaffold[y][x] == "#" and scaffold[y - 1][x] == "#"
                and scaffold[y + 1][x] == "#" and scaffold[y][x - 1] == "#"
                and scaffold[y][x + 1] == "#"):
            intersections.append((x, y))
alignments = [math.prod(x) for x in intersections]
print(sum(alignments))  # 8520

# part 2
droid.reset()
droid.intcode[0] = 2