예제 #1
0
 def test_larger_example_3(self):
     program = Intcode.from_file("./data/day_05/larger_example.txt",
                                 user_input=[
                                     10,
                                 ])
     output = program.execute()
     self.assertEqual(output, [1001])
예제 #2
0
def main():
    arcade = Intcode.from_file('input_13.txt')
    screen_control_sequences = arcade()
    print('number of block tiles:',
          len(track_screen(screen_control_sequences, TileId.BLOCK)))

    arcade.program[0] = 2
    player = Player()
    player.play(arcade)
예제 #3
0
 def __getitem__(self, item):
     if item < len(self.phases):
         phase = self.phases[item]
         if item == 0:
             user_input = [phase, self.input_value]
         else:
             user_input = [phase, self[item - 1]]
         amplifier = Intcode.from_file(self.path, user_input=user_input)
         return amplifier.execute()[0]
     else:
         raise IndexError('Series index out of range.')
예제 #4
0
def test__part_2():
    output = Intcode.from_file('input_05.txt').run([5])
    assert output == [11956381]
예제 #5
0
    @classmethod
    def from_file(cls, filename):
        data = []
        with open(filename, "r") as fh:
            for l in fh:
                data.append(l.rstrip())
        return cls(data)


if __name__ == '__main__':
    test = Grid.from_file("test1.txt")
    test.print_data()
    print(test.find_intersections())
    print(",".join(test.walk_path()))

    ascii_intcode = Intcode.from_file("input.txt")
    inp = Grid.from_intcode(ascii_intcode)
    inp.print_data()
    print(inp.find_intersections())
    inp_path = ",".join(inp.walk_path())
    print(inp_path)

    # figured this out by hand
    sub = {
        "A": "L,12,L,8,L,8",
        "B": "R,4,L,12,L,12,R,6",
        "C": "L,12,R,4,L,12,R,6"
    }
    s = inp_path
    for rep, patt in sub.items():
        s = s.replace(patt, rep)
예제 #6
0
def test__part_1():
    output = Intcode.from_file('input_05.txt').run([1])
    assert output == [0, 0, 0, 0, 0, 0, 0, 0, 0, 5821753]
예제 #7
0
 def __init__(self, filename, debug=0):
     self.intcode = Intcode.from_file(filename, debug=debug)
     self.process = self.intcode.create_process()
     self.data = defaultdict(int)
     self.current = Point(0, 0)
     self.dir = 0
예제 #8
0
 def __init__(self, x, y, filename):
     self.x = x
     self.y = y
     self.intcode = Intcode.from_file(filename)
     self.process = self.intcode.create_process()
예제 #9
0
 def __init__(self, filename):
     self.intcode = Intcode.from_file(filename)
예제 #10
0
 def __init__(self, nic_code_file, idle_tries=10):
     self.nic_code = Intcode.from_file(nic_code_file)
     self.nodes = self._create_nodes()
     self.nat_packet = None
     self.nat_y_values = set()
     self.idle_tries = idle_tries
예제 #11
0
 def __init__(self):
     self.panels = defaultdict(Panel)
     self.intcode = Intcode.from_file("adv11_input.txt")
     self.x = 0
     self.y = 0
     self.direction = DIR_UP
예제 #12
0
 def __init__(self, filename):
     self.intcode = Intcode.from_file(filename)
     self.process = None
     self.data = defaultdict(int)
     self.xmax = 0
     self.ymax = 0
예제 #13
0
        self.assertEqual(output, [1000])

    def test_larger_example_3(self):
        program = Intcode.from_file("./data/day_05/larger_example.txt",
                                    user_input=[
                                        10,
                                    ])
        output = program.execute()
        self.assertEqual(output, [1001])


# %%
unittest.main(argv=['ignored', '-v'], exit=False)

# %%
solution = Intcode.from_file("data/day_05/input.txt", user_input=[1])

# %%
result = solution.execute()

# %%
result

# %%
part2 = Intcode.from_file("data/day_05/input.txt", user_input=[5])

# %%
part2.execute()

# %%
예제 #14
0
def main():
    diagnostic = Intcode.from_file('input_05.txt')
    print('air conditioner:', diagnostic(1))
    diagnostic.trace_execution = True
    print('thermal radiator controller:', diagnostic(5))
    diagnostic.print_trace()
예제 #15
0
 def __init__(self):
     self.intcode = Intcode.from_file("adv17_input.txt")
     self.scaffold_map = []
     self.height = 0
     self.width = 0
예제 #16
0
"""Day 15: Oxygen System."""

from pathlib import Path

from oxygen_system import RepairDroid, oxygen_propagation
from intcode import Intcode

# --- Puzzle input ---
input_file = Path(__file__).parent / "repair_droid_program.txt"
program = Intcode.from_file(input_file)

# --- Part 1 ---
droid = RepairDroid(program)
droid.explore()
droid.find_path()
droid.show_area()
steps = len(droid.path) - 1
print(f"Minimum {steps} steps are required to move to the Oxygen System.")
assert steps == 404

# --- Part 2 ---
oxygenation_time = oxygen_propagation(droid.area)
print(f"It will take {oxygenation_time} minutes to fill oxygen everywhere.")
assert oxygenation_time == 406
예제 #17
0
def main():
    droid = Intcode.from_file('input_15.txt')
    droid.stack_trace_on_error = False
    print('Shortest path length:', find_shortest_path_length([], droid) - 1)
예제 #18
0
"""Day 11: Space Police."""

from pathlib import Path

import matplotlib.pyplot as plt

from intcode import Intcode
from painting_robot import PaintingRobot

# Input
input_file = Path(__file__).parent / 'painting_robot_program.txt'
robot_brain = Intcode.from_file(input_file)

# Part 1:
robot = PaintingRobot()
panels = robot.run(robot_brain)
print("Amount of panels painted:", len(panels))
assert len(panels) == 1863

# Part 2:
robot = PaintingRobot(start='white')
robot_brain.reset()
panels = robot.run(robot_brain)

xx = [p[0] for p, c in panels.items() if c]
yy = [p[1] for p, c in panels.items() if c]
plt.rcParams['toolbar'] = 'None'
_, ax = plt.subplots(figsize=(4, 0.6), facecolor='k')
ax.set_facecolor('k')
ax.plot(xx, yy, 'ws')
plt.show()  # BLULZJLZ
예제 #19
0
def part1(filename="adv9_input.txt"):
    intcode = Intcode.from_file(filename, inputs=[1])
    intcode.run()
    print(intcode.outputs)
예제 #20
0
if '..' not in sys.path:
    sys.path.append('..')

from intcode import Intcode

print("test1")
test1 = Intcode("109,1,204,-1,1001,100,1,100,1008,100,16,101,1006,101,0,99",
                debug=1)
test1.print_data()
print(test1.run())

print()
print("test2")
test2 = Intcode("1102,34915192,34915192,7,4,7,99,0", debug=1)
test2.print_data()
print(test2.run())

print()
print("test3")
test3 = Intcode("104,1125899906842624,99", debug=1)
test3.print_data()
print(test3.run())

print()
print("part #1")
inp = Intcode.from_file("input.txt", debug=1)
print(inp.run(inp=[1]))

print()
print("part #2")
inp.run(inp=[2])
예제 #21
0
 def __init__(self, filename, commands):
     self.intcode = Intcode.from_file(filename)
     self.process = self.intcode.create_process()
     self.process.set_ascii_input(commands)
예제 #22
0
        program.execute()
        self.assertEqual(program.opcodes, [30, 1, 1, 4, 2, 5, 6, 0, 99])


# %%
class TestDay2(unittest.TestCase):
    def test_instruction(self):
        program = Intcode([1, 0, 0, 0, 99])
        self.assertEqual(program.instruction, [1, 0, 0, 0])


# %%
unittest.main(argv=['ignored', '-v'], exit=False)

# %%
solution = Intcode.from_file("data/day_02/input.txt")

# %%
solution.initialize_memory(12, 2)
solution.execute()
solution.opcodes[0]

# %%
for noun in range(99):
    for verb in range(99):
        program = Intcode.from_file("data/day_02/input.txt")
        program.initialize_memory(noun, verb)
        program.execute()
        if program.opcodes[0] == 19690720:
            print(f"{100*noun + verb}")
예제 #23
0
def test__part_1():
    boost = Intcode.from_file('input_09.txt')
    assert boost(1) == [2932210790]
예제 #24
0
def parse_input(filename):
    return Intcode.from_file(Path(__file__).parent / filename)
예제 #25
0
 def __init__(self, filename="adv13_input.txt"):
     self.intcode = Intcode.from_file(filename)
     self.score = None
     self.ball_coords = None
     self.paddle_coords = None
예제 #26
0
def main():
    boost = Intcode.from_file('input_09.txt')
    print('BOOST keycode:', boost(1))
    print('BOOST coordinates of the distress signal:', boost(2))
예제 #27
0
 def from_file(filename="adv15_input.txt"):
     intcode = Intcode.from_file(filename)
     return RepairDroid(intcode)