Exemplo n.º 1
0
 def __init__(self, program_code):
     """
     Configure an intcode machine for ASCII input to play Adventure - yay ! 
     """
     self.compute = ComputeEngine(program_code)
     self.compute.attach_input_device(self)
     self.compute.attach_output_device(self)
     self.current_output = ''
     self.input = ''
     self.alert = None
Exemplo n.º 2
0
 def __init__(self, network, program_code, network_id):
     """
     Pass the network id of this node 0-49, which will be the first input byte 
     """
     self.compute = ComputeEngine(program_code)
     self.compute.attach_input_device(self)
     self.compute.attach_output_device(self)
     self.network = network
     self.network_id = network_id
     self.input_buffer = [network_id]
     self.network_destination = None
     self.send_packet = []
     self.read_write_operation_history = []
Exemplo n.º 3
0
def calculate_one_signal(program_code, amplifier_settings, initial_input):
    """ 
      Run the program X times where X is the number of settings in amplifier_settings
      Each run should have the input to the intcode machine set to [setting, X]
      On the first run, the X value is passed in initial_input
      After the first execution, the output value from the previous run becomes the X value 
    """
    value_X = initial_input
    for this_amplifier_setting in amplifier_settings:
        print(f"executing for {this_amplifier_setting},{value_X}")
        if has_cached_result(this_amplifier_setting, value_X):
            value_X = get_cached_result(this_amplifier_setting, value_X)
        else:
            c = ComputeEngine()
            c.load_memory(program_code)
            c.load_data([this_amplifier_setting, value_X])
            c.run(False)
            new_value_X = c.output_buffer[0]
            store_result_in_cache(this_amplifier_setting, value_X, new_value_X)
            value_X = new_value_X
    return value_X
Exemplo n.º 4
0
def calculate_one_signal(program_code, amplifier_settings, initial_input):
    """ 
      Setup X instances of the machine with clean code 
      initial inputs to the program are [setting, 0] for the first one, then each subsequent one 
      will get [setting, X] where X is the output from the previous machine.
      With the output of the last machine we need to loop round to the first machine until 
      the final machine halts the program, at which time the last output of the final machine 
      is presumably the answer - we shall see. 
    """
    # stand up all the machines
    machines = [
        ComputeEngine(program_code, [amplifier_setting])
        for amplifier_setting in amplifier_settings
    ]

    target_machine_idx = 0
    value_X = initial_input

    # start to loop
    halted = False
    while not halted:
        # run this machine with the new input
        machines[target_machine_idx].add_data([value_X])
        # execute until the next output instruction or halt
        this_result = machines[target_machine_idx].run_to_output(False)
        # did we finish ?
        print(
            f"Executed machine {target_machine_idx}, with input {value_X} and got result {this_result}"
        )
        if this_result is None:
            # we are done, the last input of the last machine we hope
            halted = True
        else:
            # next machine with this input
            target_machine_idx += 1
            if target_machine_idx >= len(machines):
                target_machine_idx = 0
            value_X = this_result

    return value_X
Exemplo n.º 5
0
#  999,1105,1,46,1101,1000,1,20,4,20,1105,1,46,98,99
#  The above example program uses an input instruction to ask for a single number. 
#  The program will then output 999 if the input value is below 8, output 1000 if the input value 
#  is equal to 8, or output 1001 if the input value is greater than 8.
#  
#  This time, when the TEST diagnostic program runs its input instruction to get the ID of the system 
#  to test, provide it 5, the ID for the ship's thermal radiator controller. This diagnostic test 
#  suite only outputs one number, the diagnostic code.
#  
#  What is the diagnostic code for system ID 5?
#  
#  

puzzle_input = '3,225,1,225,6,6,1100,1,238,225,104,0,1101,48,82,225,102,59,84,224,1001,224,-944,224,4,224,102,8,223,223,101,6,224,224,1,223,224,223,1101,92,58,224,101,-150,224,224,4,224,102,8,223,223,1001,224,3,224,1,224,223,223,1102,10,89,224,101,-890,224,224,4,224,1002,223,8,223,1001,224,5,224,1,224,223,223,1101,29,16,225,101,23,110,224,1001,224,-95,224,4,224,102,8,223,223,1001,224,3,224,1,223,224,223,1102,75,72,225,1102,51,8,225,1102,26,16,225,1102,8,49,225,1001,122,64,224,1001,224,-113,224,4,224,102,8,223,223,1001,224,3,224,1,224,223,223,1102,55,72,225,1002,174,28,224,101,-896,224,224,4,224,1002,223,8,223,101,4,224,224,1,224,223,223,1102,57,32,225,2,113,117,224,101,-1326,224,224,4,224,102,8,223,223,101,5,224,224,1,223,224,223,1,148,13,224,101,-120,224,224,4,224,1002,223,8,223,101,7,224,224,1,223,224,223,4,223,99,0,0,0,677,0,0,0,0,0,0,0,0,0,0,0,1105,0,99999,1105,227,247,1105,1,99999,1005,227,99999,1005,0,256,1105,1,99999,1106,227,99999,1106,0,265,1105,1,99999,1006,0,99999,1006,227,274,1105,1,99999,1105,1,280,1105,1,99999,1,225,225,225,1101,294,0,0,105,1,0,1105,1,99999,1106,0,300,1105,1,99999,1,225,225,225,1101,314,0,0,106,0,0,1105,1,99999,8,677,226,224,102,2,223,223,1006,224,329,101,1,223,223,107,677,677,224,1002,223,2,223,1006,224,344,101,1,223,223,8,226,677,224,102,2,223,223,1006,224,359,101,1,223,223,107,226,226,224,102,2,223,223,1005,224,374,1001,223,1,223,1108,677,226,224,1002,223,2,223,1006,224,389,101,1,223,223,107,677,226,224,102,2,223,223,1006,224,404,1001,223,1,223,1107,226,677,224,1002,223,2,223,1006,224,419,1001,223,1,223,108,677,677,224,102,2,223,223,1005,224,434,1001,223,1,223,1008,677,226,224,1002,223,2,223,1006,224,449,1001,223,1,223,7,226,677,224,1002,223,2,223,1006,224,464,1001,223,1,223,1007,677,677,224,102,2,223,223,1005,224,479,1001,223,1,223,1007,226,226,224,1002,223,2,223,1005,224,494,1001,223,1,223,108,226,226,224,1002,223,2,223,1005,224,509,1001,223,1,223,1007,226,677,224,1002,223,2,223,1006,224,524,101,1,223,223,1107,677,677,224,102,2,223,223,1005,224,539,101,1,223,223,1107,677,226,224,102,2,223,223,1005,224,554,1001,223,1,223,108,677,226,224,1002,223,2,223,1006,224,569,1001,223,1,223,1108,226,677,224,1002,223,2,223,1006,224,584,101,1,223,223,8,677,677,224,1002,223,2,223,1006,224,599,1001,223,1,223,1008,226,226,224,102,2,223,223,1006,224,614,101,1,223,223,7,677,677,224,1002,223,2,223,1006,224,629,101,1,223,223,1008,677,677,224,102,2,223,223,1005,224,644,101,1,223,223,7,677,226,224,1002,223,2,223,1005,224,659,101,1,223,223,1108,226,226,224,102,2,223,223,1006,224,674,1001,223,1,223,4,223,99,226'

import os 
import sys 
sys.path.append("c:\\development\\advent-of-code-2019")
print(sys.path)

from compute_engine.engine import ComputeEngine

c = ComputeEngine()
c.load_memory(puzzle_input)
c.load_data([5])
c.run(True)




igen = [InstructionLooper() for _ in range(max_instructions)]

while (True):
    # increment the instructions
    i = 0
    while igen[i].increment():
        i += 1
    # generate the command
    instructions = [igen[i].output() for i in range(max_instructions)]
    combined = "".join(instructions)
    combined += "RUN\n"
    print(combined.replace('\n', ','))
    # execute the command, see if we win..

    # Build the ASCII Controller
    controller = AsciiController()
    controller.set_output(False)

    #spring_script = 'NOT B T\nOR T J\nNOT C T\nOR T J\nAND D J\nNOT A T\nOR T J\nWALK\n'
    #spring_script = 'NOT B T\nOR T J\nNOT C T\nOR T J\nAND D J\nNOT A T\nOR T J\nRUN\n'

    controller.set_input(combined)

    # build the computer and attach the screen
    c = ComputeEngine(program_code)
    # attach the controls
    c.attach_output_device(controller)
    c.attach_input_device(controller)
    c.run(False, False)
Exemplo n.º 7
0
                elif y < self.target_y:
                    # or south
                    result = MOVE_SOUTH
                    #print("going back South")
                elif x > self.target_x:
                    result = MOVE_WEST
                    #print("Go WEST!!! (back west that is)")
                else:
                    result = MOVE_EAST
                    #print("Going home east")

        #sleep(2)
        return result


import sys
sys.path.append("c:\\development\\advent-of-code-2019")
from compute_engine.engine import ComputeEngine

puzzle_program = '3,1033,1008,1033,1,1032,1005,1032,31,1008,1033,2,1032,1005,1032,58,1008,1033,3,1032,1005,1032,81,1008,1033,4,1032,1005,1032,104,99,1002,1034,1,1039,101,0,1036,1041,1001,1035,-1,1040,1008,1038,0,1043,102,-1,1043,1032,1,1037,1032,1042,1105,1,124,1002,1034,1,1039,101,0,1036,1041,1001,1035,1,1040,1008,1038,0,1043,1,1037,1038,1042,1105,1,124,1001,1034,-1,1039,1008,1036,0,1041,101,0,1035,1040,101,0,1038,1043,1002,1037,1,1042,1105,1,124,1001,1034,1,1039,1008,1036,0,1041,1002,1035,1,1040,102,1,1038,1043,1002,1037,1,1042,1006,1039,217,1006,1040,217,1008,1039,40,1032,1005,1032,217,1008,1040,40,1032,1005,1032,217,1008,1039,39,1032,1006,1032,165,1008,1040,39,1032,1006,1032,165,1101,0,2,1044,1105,1,224,2,1041,1043,1032,1006,1032,179,1102,1,1,1044,1106,0,224,1,1041,1043,1032,1006,1032,217,1,1042,1043,1032,1001,1032,-1,1032,1002,1032,39,1032,1,1032,1039,1032,101,-1,1032,1032,101,252,1032,211,1007,0,74,1044,1106,0,224,1101,0,0,1044,1106,0,224,1006,1044,247,102,1,1039,1034,102,1,1040,1035,1002,1041,1,1036,1002,1043,1,1038,1002,1042,1,1037,4,1044,1105,1,0,15,82,44,17,88,23,99,42,83,68,98,44,75,66,15,14,89,20,34,89,18,1,84,70,84,69,55,89,65,10,76,63,83,20,80,60,48,47,98,65,82,84,68,89,52,76,63,86,61,75,4,52,82,79,24,28,93,94,95,40,66,76,81,50,31,94,81,54,19,91,92,61,18,28,79,77,43,69,19,5,87,35,14,23,94,10,76,32,73,90,20,86,67,90,80,8,86,25,89,89,26,48,37,81,49,25,87,92,17,46,84,96,95,60,79,52,19,13,93,30,93,99,17,13,89,96,36,93,81,89,18,2,97,42,45,63,86,20,26,76,97,29,75,56,7,97,93,2,78,9,79,8,57,84,38,80,53,98,89,34,71,85,17,96,50,31,93,64,7,81,72,85,32,83,31,99,69,90,88,33,88,81,41,80,46,47,93,75,34,95,8,98,24,7,76,77,17,23,95,72,82,98,24,91,95,50,38,92,91,32,95,40,77,80,84,82,7,90,23,13,92,40,82,37,80,56,24,79,99,64,90,55,58,46,33,4,88,92,7,84,19,45,16,75,94,40,93,21,87,94,79,39,83,52,92,14,21,77,82,5,84,85,48,75,19,26,91,28,99,87,81,86,24,53,98,52,25,2,75,39,82,24,51,77,47,92,53,94,27,34,85,22,25,36,92,79,29,2,10,19,95,13,96,82,56,99,3,91,62,99,43,49,7,91,96,77,89,7,99,86,24,92,57,24,49,3,96,77,35,75,11,86,21,1,82,67,84,90,75,96,9,83,1,47,78,7,98,30,11,88,52,78,58,98,47,90,46,78,14,77,88,3,97,87,70,75,24,98,5,80,87,93,95,22,37,59,85,23,41,89,91,9,7,90,61,3,95,96,92,25,57,47,38,88,14,15,84,31,79,20,79,77,22,33,90,70,89,78,51,24,93,81,21,79,82,17,75,88,78,26,87,24,38,96,50,81,6,46,93,39,91,92,81,39,91,5,79,58,9,87,50,83,63,87,2,29,92,37,81,55,59,99,91,35,9,96,18,82,66,4,89,44,87,92,6,79,88,9,9,63,88,71,77,91,35,29,87,87,51,20,94,19,57,93,72,89,4,77,10,87,20,67,80,79,71,1,75,28,87,88,87,55,37,80,85,5,55,5,97,12,62,88,82,27,6,99,93,42,91,16,75,80,6,20,96,6,84,6,46,84,23,92,93,32,90,79,3,54,7,97,92,92,33,79,9,5,10,90,76,19,76,1,85,83,58,2,91,83,77,59,63,89,26,97,67,96,52,88,62,65,23,91,94,51,31,80,24,5,72,40,81,9,85,79,12,98,44,45,81,25,30,60,5,76,92,62,18,32,78,25,16,76,97,18,96,39,96,60,78,78,47,99,48,82,98,57,96,98,73,89,18,12,91,8,66,85,57,94,22,76,88,98,39,58,96,91,61,98,89,7,77,91,13,96,20,86,2,88,91,27,75,32,29,79,51,81,4,86,10,37,79,84,67,49,75,20,94,91,23,33,92,38,91,37,76,79,55,91,43,80,25,98,77,91,88,44,15,97,45,3,86,73,87,30,91,62,80,80,16,85,54,88,54,75,88,65,18,85,22,90,79,36,10,77,86,65,30,38,85,3,90,44,48,75,81,80,32,59,90,91,41,95,72,79,11,66,26,96,20,4,68,88,23,95,31,98,12,98,56,94,95,80,68,78,39,79,93,85,55,96,4,77,14,80,46,95,84,84,6,93,35,95,46,85,92,81,69,85,92,87,0,0,21,21,1,10,1,0,0,0,0,0,0'

# build a solver
solver = MazeSolver()

# build the computer and attach the screen
c = ComputeEngine(puzzle_program)
# attach the controls
c.attach_output_device(solver)
c.attach_input_device(solver)
c.run(False, False)
Exemplo n.º 8
0
    second_reference = my_obj
    print(f"myobj is {my_obj}, second_reference is {second_reference}")

    test_value = my_obj.provide_input()
    print(f"test_value is {test_value}")

    # let's paint a thing 
    second_reference.receive_output(1)
    print(f"myobj is {my_obj}, second_reference is {second_reference}")

# ok - everything looks like it works - time to plug this into the Intcode and see what happens 

import sys 
sys.path.append("c:\\development\\advent-of-code-2019")
from compute_engine.engine import ComputeEngine

program_code = '3,8,1005,8,301,1106,0,11,0,0,0,104,1,104,0,3,8,102,-1,8,10,1001,10,1,10,4,10,108,1,8,10,4,10,102,1,8,28,1006,0,98,3,8,102,-1,8,10,101,1,10,10,4,10,1008,8,1,10,4,10,101,0,8,54,2,1001,6,10,1,108,1,10,3,8,1002,8,-1,10,101,1,10,10,4,10,1008,8,0,10,4,10,1002,8,1,84,3,8,102,-1,8,10,1001,10,1,10,4,10,108,1,8,10,4,10,101,0,8,105,1006,0,94,2,7,20,10,2,5,7,10,3,8,1002,8,-1,10,1001,10,1,10,4,10,1008,8,0,10,4,10,102,1,8,139,1006,0,58,2,1003,16,10,1,6,10,10,3,8,1002,8,-1,10,101,1,10,10,4,10,1008,8,0,10,4,10,102,1,8,172,2,107,12,10,3,8,102,-1,8,10,1001,10,1,10,4,10,108,0,8,10,4,10,101,0,8,197,1006,0,34,3,8,102,-1,8,10,101,1,10,10,4,10,1008,8,1,10,4,10,102,1,8,223,1006,0,62,3,8,102,-1,8,10,101,1,10,10,4,10,1008,8,1,10,4,10,1001,8,0,248,1,7,7,10,1006,0,64,2,1008,5,10,3,8,1002,8,-1,10,1001,10,1,10,4,10,108,0,8,10,4,10,102,1,8,280,101,1,9,9,1007,9,997,10,1005,10,15,99,109,623,104,0,104,1,21102,1,387508351636,1,21101,318,0,0,1106,0,422,21102,1,838480007948,1,21101,0,329,0,1106,0,422,3,10,104,0,104,1,3,10,104,0,104,0,3,10,104,0,104,1,3,10,104,0,104,1,3,10,104,0,104,0,3,10,104,0,104,1,21101,0,235190525123,1,21101,0,376,0,1105,1,422,21101,0,106505084123,1,21101,0,387,0,1106,0,422,3,10,104,0,104,0,3,10,104,0,104,0,21101,0,838324605292,1,21102,1,410,0,1105,1,422,21102,709496668940,1,1,21102,421,1,0,1105,1,422,99,109,2,22101,0,-1,1,21102,1,40,2,21101,0,453,3,21102,443,1,0,1106,0,486,109,-2,2105,1,0,0,1,0,0,1,109,2,3,10,204,-1,1001,448,449,464,4,0,1001,448,1,448,108,4,448,10,1006,10,480,1102,1,0,448,109,-2,2106,0,0,0,109,4,2101,0,-1,485,1207,-3,0,10,1006,10,503,21102,0,1,-3,22102,1,-3,1,21201,-2,0,2,21101,1,0,3,21102,1,522,0,1106,0,527,109,-4,2105,1,0,109,5,1207,-3,1,10,1006,10,550,2207,-4,-2,10,1006,10,550,21202,-4,1,-4,1106,0,618,22102,1,-4,1,21201,-3,-1,2,21202,-2,2,3,21102,569,1,0,1106,0,527,21202,1,1,-4,21101,0,1,-1,2207,-4,-2,10,1006,10,588,21101,0,0,-1,22202,-2,-1,-2,2107,0,-3,10,1006,10,610,22101,0,-1,1,21101,0,610,0,106,0,485,21202,-2,-1,-2,22201,-4,-2,-4,109,-5,2106,0,0'

painter = HullPaintingModule()

c = ComputeEngine(program_code)
c.attach_input_device(painter)
c.attach_output_device(painter)
c.run(False)
#c.dump_memory()

print(f"After painting the ship : {painter}")



Exemplo n.º 9
0
        result = 0
        for x in range(self.min_x, self.max_x + 1):
            for y in range(self.min_y, self.max_y + 1):
                if self.is_intersection(x, y):
                    print(f"Found an intersection at {x},{y}")
                    result += x * y
                    self.store_tile(x, y, TILE_INTERSECTION)
        print(f"Total alignment parameters are {result}")
        return result


puzzle_program = '1,330,331,332,109,3974,1102,1182,1,15,1101,1475,0,24,1001,0,0,570,1006,570,36,101,0,571,0,1001,570,-1,570,1001,24,1,24,1106,0,18,1008,571,0,571,1001,15,1,15,1008,15,1475,570,1006,570,14,21102,1,58,0,1105,1,786,1006,332,62,99,21101,333,0,1,21102,73,1,0,1105,1,579,1102,0,1,572,1101,0,0,573,3,574,101,1,573,573,1007,574,65,570,1005,570,151,107,67,574,570,1005,570,151,1001,574,-64,574,1002,574,-1,574,1001,572,1,572,1007,572,11,570,1006,570,165,101,1182,572,127,1002,574,1,0,3,574,101,1,573,573,1008,574,10,570,1005,570,189,1008,574,44,570,1006,570,158,1105,1,81,21102,340,1,1,1105,1,177,21101,0,477,1,1106,0,177,21102,1,514,1,21101,0,176,0,1106,0,579,99,21102,184,1,0,1105,1,579,4,574,104,10,99,1007,573,22,570,1006,570,165,1002,572,1,1182,21101,0,375,1,21101,0,211,0,1105,1,579,21101,1182,11,1,21102,1,222,0,1106,0,979,21102,1,388,1,21102,1,233,0,1106,0,579,21101,1182,22,1,21101,0,244,0,1105,1,979,21101,0,401,1,21102,1,255,0,1106,0,579,21101,1182,33,1,21102,1,266,0,1106,0,979,21102,414,1,1,21102,277,1,0,1105,1,579,3,575,1008,575,89,570,1008,575,121,575,1,575,570,575,3,574,1008,574,10,570,1006,570,291,104,10,21102,1182,1,1,21102,1,313,0,1106,0,622,1005,575,327,1101,1,0,575,21101,327,0,0,1105,1,786,4,438,99,0,1,1,6,77,97,105,110,58,10,33,10,69,120,112,101,99,116,101,100,32,102,117,110,99,116,105,111,110,32,110,97,109,101,32,98,117,116,32,103,111,116,58,32,0,12,70,117,110,99,116,105,111,110,32,65,58,10,12,70,117,110,99,116,105,111,110,32,66,58,10,12,70,117,110,99,116,105,111,110,32,67,58,10,23,67,111,110,116,105,110,117,111,117,115,32,118,105,100,101,111,32,102,101,101,100,63,10,0,37,10,69,120,112,101,99,116,101,100,32,82,44,32,76,44,32,111,114,32,100,105,115,116,97,110,99,101,32,98,117,116,32,103,111,116,58,32,36,10,69,120,112,101,99,116,101,100,32,99,111,109,109,97,32,111,114,32,110,101,119,108,105,110,101,32,98,117,116,32,103,111,116,58,32,43,10,68,101,102,105,110,105,116,105,111,110,115,32,109,97,121,32,98,101,32,97,116,32,109,111,115,116,32,50,48,32,99,104,97,114,97,99,116,101,114,115,33,10,94,62,118,60,0,1,0,-1,-1,0,1,0,0,0,0,0,0,1,50,26,0,109,4,1201,-3,0,587,20102,1,0,-1,22101,1,-3,-3,21102,0,1,-2,2208,-2,-1,570,1005,570,617,2201,-3,-2,609,4,0,21201,-2,1,-2,1106,0,597,109,-4,2106,0,0,109,5,2101,0,-4,630,20101,0,0,-2,22101,1,-4,-4,21101,0,0,-3,2208,-3,-2,570,1005,570,781,2201,-4,-3,653,20101,0,0,-1,1208,-1,-4,570,1005,570,709,1208,-1,-5,570,1005,570,734,1207,-1,0,570,1005,570,759,1206,-1,774,1001,578,562,684,1,0,576,576,1001,578,566,692,1,0,577,577,21102,702,1,0,1106,0,786,21201,-1,-1,-1,1106,0,676,1001,578,1,578,1008,578,4,570,1006,570,724,1001,578,-4,578,21102,731,1,0,1105,1,786,1106,0,774,1001,578,-1,578,1008,578,-1,570,1006,570,749,1001,578,4,578,21101,756,0,0,1105,1,786,1106,0,774,21202,-1,-11,1,22101,1182,1,1,21102,774,1,0,1105,1,622,21201,-3,1,-3,1106,0,640,109,-5,2105,1,0,109,7,1005,575,802,20102,1,576,-6,20101,0,577,-5,1105,1,814,21101,0,0,-1,21101,0,0,-5,21101,0,0,-6,20208,-6,576,-2,208,-5,577,570,22002,570,-2,-2,21202,-5,51,-3,22201,-6,-3,-3,22101,1475,-3,-3,2102,1,-3,843,1005,0,863,21202,-2,42,-4,22101,46,-4,-4,1206,-2,924,21102,1,1,-1,1105,1,924,1205,-2,873,21102,1,35,-4,1106,0,924,1202,-3,1,878,1008,0,1,570,1006,570,916,1001,374,1,374,1201,-3,0,895,1101,0,2,0,2101,0,-3,902,1001,438,0,438,2202,-6,-5,570,1,570,374,570,1,570,438,438,1001,578,558,921,21002,0,1,-4,1006,575,959,204,-4,22101,1,-6,-6,1208,-6,51,570,1006,570,814,104,10,22101,1,-5,-5,1208,-5,49,570,1006,570,810,104,10,1206,-1,974,99,1206,-1,974,1102,1,1,575,21101,973,0,0,1105,1,786,99,109,-7,2105,1,0,109,6,21101,0,0,-4,21102,0,1,-3,203,-2,22101,1,-3,-3,21208,-2,82,-1,1205,-1,1030,21208,-2,76,-1,1205,-1,1037,21207,-2,48,-1,1205,-1,1124,22107,57,-2,-1,1205,-1,1124,21201,-2,-48,-2,1105,1,1041,21102,1,-4,-2,1106,0,1041,21101,0,-5,-2,21201,-4,1,-4,21207,-4,11,-1,1206,-1,1138,2201,-5,-4,1059,2102,1,-2,0,203,-2,22101,1,-3,-3,21207,-2,48,-1,1205,-1,1107,22107,57,-2,-1,1205,-1,1107,21201,-2,-48,-2,2201,-5,-4,1090,20102,10,0,-1,22201,-2,-1,-2,2201,-5,-4,1103,2102,1,-2,0,1106,0,1060,21208,-2,10,-1,1205,-1,1162,21208,-2,44,-1,1206,-1,1131,1106,0,989,21101,0,439,1,1105,1,1150,21101,477,0,1,1106,0,1150,21102,1,514,1,21102,1,1149,0,1105,1,579,99,21101,1157,0,0,1106,0,579,204,-2,104,10,99,21207,-3,22,-1,1206,-1,1138,2101,0,-5,1176,2102,1,-4,0,109,-6,2106,0,0,32,5,46,1,3,1,46,1,3,1,46,1,3,1,46,1,3,1,46,1,3,1,40,11,40,1,5,1,44,1,5,1,44,1,5,1,44,1,5,1,44,1,5,1,40,11,40,1,3,1,46,1,3,1,46,1,3,1,46,1,3,9,38,1,11,1,26,1,11,1,11,1,26,1,11,1,11,1,26,1,11,5,7,1,26,1,15,1,7,1,26,1,15,1,7,1,26,1,15,1,7,1,26,1,11,7,5,1,26,1,11,1,3,1,1,1,5,1,26,1,9,13,1,1,3,13,10,1,9,1,1,1,3,1,1,1,3,1,1,1,3,1,22,5,5,1,1,13,3,1,26,1,5,1,5,1,1,1,3,1,5,1,26,1,5,1,5,7,5,1,26,1,5,1,7,1,9,1,26,1,5,1,7,1,9,1,26,1,5,1,7,1,9,1,26,1,5,1,7,11,26,1,5,1,34,11,5,1,34,1,15,1,34,1,5,9,1,9,26,1,5,1,7,1,9,1,26,1,5,1,7,1,9,1,26,1,5,1,7,1,9,1,22,11,7,1,9,1,22,1,3,1,13,1,9,1,22,1,3,1,13,1,9,1,22,1,3,1,13,1,9,1,22,1,3,1,13,1,9,1,22,1,3,1,13,1,9,1,22,5,13,11,22'

# Build the ASCII Controller
controller = AsciiController()

# build the computer and attach the screen
c = ComputeEngine(puzzle_program)
# attach the controls
c.attach_output_device(controller)
#c.attach_input_device(solver)
c.run(False, False)

controller.print()

alignment = controller.calculate_alignment_parameters()

controller.print(rulers=True)

print(f"Alignment is : {alignment}")
Exemplo n.º 10
0
class NetworkComputeEngine:
    def __init__(self, network, program_code, network_id):
        """
        Pass the network id of this node 0-49, which will be the first input byte 
        """
        self.compute = ComputeEngine(program_code)
        self.compute.attach_input_device(self)
        self.compute.attach_output_device(self)
        self.network = network
        self.network_id = network_id
        self.input_buffer = [network_id]
        self.network_destination = None
        self.send_packet = []
        self.read_write_operation_history = []

    def only_reading(self):
        """
        Return true if the last X read/write operations were all read
        """
        result = False
        if 0 == len(self.input_buffer):
            if len(self.read_write_operation_history
                   ) >= RELEVANT_SEQUENTIAL_EVENTS:
                # ok, we have enough history, are they all read events ?
                read_results = [
                    EVENT_READ_NOINPUT == x
                    for x in self.read_write_operation_history
                ]
                result = all(read_results)
        return result

    def store_read_write_op(self, read_write):
        """
        Store the next thing in the read/write list 
        """
        self.read_write_operation_history.append(read_write)
        self.read_write_operation_history = self.read_write_operation_history[
            -RELEVANT_SEQUENTIAL_EVENTS_HISTORY:]
        #print(f'Sequential events:{"".join(self.read_write_operation_history)}')

    def receive_network_input(self, the_value):
        """
        Add the thing to the input buffer 
        """
        self.input_buffer.append(the_value)

    def send_network_packet(self, the_value):
        """
        Send a packet to the destination address 
        """
        self.send_packet.append(the_value)
        if 2 == len(self.send_packet):
            # Time to send yo
            self.network.send(self.network_destination, self.send_packet[0])
            self.network.send(self.network_destination, self.send_packet[1])
            self.network_destination = None
            self.send_packet = []

    def set_destination_address(self, destination_address):
        """
        we don't have a destination address set, so update it
        """
        self.network_destination = destination_address

    def step(self, debug_step=True, advanced_debug=False):
        """
        Step this machine
        """
        return self.compute.step(debug_step, advanced_debug)

    def receive_output(self, output_value):
        """
        Intcode computer interface - receives the output value
        in this case it is a three part process: network address, x, y  
        """
        if self.network_destination is None:
            self.set_destination_address(output_value)
        else:
            self.send_network_packet(output_value)
        self.store_read_write_op(EVENT_WRITE)

    def provide_input(self):
        """
        Provide the next value in the input array, if there is none then send -1
        """
        result = -1
        if 0 < len(self.input_buffer):
            result = self.input_buffer[0]
            self.input_buffer = self.input_buffer[1:]
            #print(f"Machine {self.network_id} is reading {result}")
            self.store_read_write_op(EVENT_READ_INPUT)
        else:
            self.store_read_write_op(EVENT_READ_NOINPUT)
        return result
Exemplo n.º 11
0
class AsciiAdventureBot:
    def __init__(self, program_code):
        """
        Configure an intcode machine for ASCII input to play Adventure - yay ! 
        """
        self.compute = ComputeEngine(program_code)
        self.compute.attach_input_device(self)
        self.compute.attach_output_device(self)
        self.current_output = ''
        self.input = ''
        self.alert = None

    def run(self):
        """Start the program"""
        self.compute.run(False, False, False)

    def receive_output(self, the_output):
        """ IntCode interface, the program is outputting an ASCII character """
        if 10 == the_output:
            print(f"{self.current_output}")
            if 'Alert!' in self.current_output:
                this_alert = self.current_output
                this_alert = this_alert.replace('A loud, robotic voice says',
                                                '')
                this_alert = this_alert.replace(
                    'and you are ejected back to the checkpoint', '')
                #this_combo = self.all_object_combos[self.this_combo_index]
                #self.combo_results[this_combo] = this_alert
                #print(f"Combo({this_combo}) -> {this_alert}")
            self.current_output = ''
        else:
            self.current_output += chr(the_output)

    def create_potential_item_combos(self, the_items):
        """
        Store all potential combinations of the items provided
        """
        result = list()
        for combo_length in range(1, len(the_items) + 1):
            this_set_of_combos = list(combinations(the_items, combo_length))
            result.extend(this_set_of_combos)
        # store the objects for later use
        self.all_object_combos = result
        self.this_combo_index = -1
        self.combo_results = dict()

    def provide_input(self):
        """
        Provide ASCII values as input
        """

        # not having the interactive session for now..
        if False:
            while 0 == len(self.input):
                new_input = input('input>').strip()
                if '' != new_input:
                    self.input += new_input + '\n'
        else:
            if 0 == len(self.input):
                # now create the commands for the next one of the sequences
                self.this_combo_index += 1
                print(
                    f"Combo will be ({self.all_object_combos[self.this_combo_index]}"
                )
                script = create_commands(
                    self.all_object_combos[self.this_combo_index])
                self.input += script

        # and now send the next input character
        result = ord(self.input[0])
        self.input = self.input[1:]
        return result

    def append_command(self, command):
        """
        Add a pre-defined command to the buffer 
        """
        self.input += command + '\n'
Exemplo n.º 12
0
    """
    return ord(c)


# seems ok for now..
test_chars = "#.0123456789LR\n"
for c in test_chars:
    print(f"ascii for {c} is {ascii_for(c)}")

puzzle_program = '1,330,331,332,109,3974,1102,1182,1,15,1101,1475,0,24,1001,0,0,570,1006,570,36,101,0,571,0,1001,570,-1,570,1001,24,1,24,1106,0,18,1008,571,0,571,1001,15,1,15,1008,15,1475,570,1006,570,14,21102,1,58,0,1105,1,786,1006,332,62,99,21101,333,0,1,21102,73,1,0,1105,1,579,1102,0,1,572,1101,0,0,573,3,574,101,1,573,573,1007,574,65,570,1005,570,151,107,67,574,570,1005,570,151,1001,574,-64,574,1002,574,-1,574,1001,572,1,572,1007,572,11,570,1006,570,165,101,1182,572,127,1002,574,1,0,3,574,101,1,573,573,1008,574,10,570,1005,570,189,1008,574,44,570,1006,570,158,1105,1,81,21102,340,1,1,1105,1,177,21101,0,477,1,1106,0,177,21102,1,514,1,21101,0,176,0,1106,0,579,99,21102,184,1,0,1105,1,579,4,574,104,10,99,1007,573,22,570,1006,570,165,1002,572,1,1182,21101,0,375,1,21101,0,211,0,1105,1,579,21101,1182,11,1,21102,1,222,0,1106,0,979,21102,1,388,1,21102,1,233,0,1106,0,579,21101,1182,22,1,21101,0,244,0,1105,1,979,21101,0,401,1,21102,1,255,0,1106,0,579,21101,1182,33,1,21102,1,266,0,1106,0,979,21102,414,1,1,21102,277,1,0,1105,1,579,3,575,1008,575,89,570,1008,575,121,575,1,575,570,575,3,574,1008,574,10,570,1006,570,291,104,10,21102,1182,1,1,21102,1,313,0,1106,0,622,1005,575,327,1101,1,0,575,21101,327,0,0,1105,1,786,4,438,99,0,1,1,6,77,97,105,110,58,10,33,10,69,120,112,101,99,116,101,100,32,102,117,110,99,116,105,111,110,32,110,97,109,101,32,98,117,116,32,103,111,116,58,32,0,12,70,117,110,99,116,105,111,110,32,65,58,10,12,70,117,110,99,116,105,111,110,32,66,58,10,12,70,117,110,99,116,105,111,110,32,67,58,10,23,67,111,110,116,105,110,117,111,117,115,32,118,105,100,101,111,32,102,101,101,100,63,10,0,37,10,69,120,112,101,99,116,101,100,32,82,44,32,76,44,32,111,114,32,100,105,115,116,97,110,99,101,32,98,117,116,32,103,111,116,58,32,36,10,69,120,112,101,99,116,101,100,32,99,111,109,109,97,32,111,114,32,110,101,119,108,105,110,101,32,98,117,116,32,103,111,116,58,32,43,10,68,101,102,105,110,105,116,105,111,110,115,32,109,97,121,32,98,101,32,97,116,32,109,111,115,116,32,50,48,32,99,104,97,114,97,99,116,101,114,115,33,10,94,62,118,60,0,1,0,-1,-1,0,1,0,0,0,0,0,0,1,50,26,0,109,4,1201,-3,0,587,20102,1,0,-1,22101,1,-3,-3,21102,0,1,-2,2208,-2,-1,570,1005,570,617,2201,-3,-2,609,4,0,21201,-2,1,-2,1106,0,597,109,-4,2106,0,0,109,5,2101,0,-4,630,20101,0,0,-2,22101,1,-4,-4,21101,0,0,-3,2208,-3,-2,570,1005,570,781,2201,-4,-3,653,20101,0,0,-1,1208,-1,-4,570,1005,570,709,1208,-1,-5,570,1005,570,734,1207,-1,0,570,1005,570,759,1206,-1,774,1001,578,562,684,1,0,576,576,1001,578,566,692,1,0,577,577,21102,702,1,0,1106,0,786,21201,-1,-1,-1,1106,0,676,1001,578,1,578,1008,578,4,570,1006,570,724,1001,578,-4,578,21102,731,1,0,1105,1,786,1106,0,774,1001,578,-1,578,1008,578,-1,570,1006,570,749,1001,578,4,578,21101,756,0,0,1105,1,786,1106,0,774,21202,-1,-11,1,22101,1182,1,1,21102,774,1,0,1105,1,622,21201,-3,1,-3,1106,0,640,109,-5,2105,1,0,109,7,1005,575,802,20102,1,576,-6,20101,0,577,-5,1105,1,814,21101,0,0,-1,21101,0,0,-5,21101,0,0,-6,20208,-6,576,-2,208,-5,577,570,22002,570,-2,-2,21202,-5,51,-3,22201,-6,-3,-3,22101,1475,-3,-3,2102,1,-3,843,1005,0,863,21202,-2,42,-4,22101,46,-4,-4,1206,-2,924,21102,1,1,-1,1105,1,924,1205,-2,873,21102,1,35,-4,1106,0,924,1202,-3,1,878,1008,0,1,570,1006,570,916,1001,374,1,374,1201,-3,0,895,1101,0,2,0,2101,0,-3,902,1001,438,0,438,2202,-6,-5,570,1,570,374,570,1,570,438,438,1001,578,558,921,21002,0,1,-4,1006,575,959,204,-4,22101,1,-6,-6,1208,-6,51,570,1006,570,814,104,10,22101,1,-5,-5,1208,-5,49,570,1006,570,810,104,10,1206,-1,974,99,1206,-1,974,1102,1,1,575,21101,973,0,0,1105,1,786,99,109,-7,2105,1,0,109,6,21101,0,0,-4,21102,0,1,-3,203,-2,22101,1,-3,-3,21208,-2,82,-1,1205,-1,1030,21208,-2,76,-1,1205,-1,1037,21207,-2,48,-1,1205,-1,1124,22107,57,-2,-1,1205,-1,1124,21201,-2,-48,-2,1105,1,1041,21102,1,-4,-2,1106,0,1041,21101,0,-5,-2,21201,-4,1,-4,21207,-4,11,-1,1206,-1,1138,2201,-5,-4,1059,2102,1,-2,0,203,-2,22101,1,-3,-3,21207,-2,48,-1,1205,-1,1107,22107,57,-2,-1,1205,-1,1107,21201,-2,-48,-2,2201,-5,-4,1090,20102,10,0,-1,22201,-2,-1,-2,2201,-5,-4,1103,2102,1,-2,0,1106,0,1060,21208,-2,10,-1,1205,-1,1162,21208,-2,44,-1,1206,-1,1131,1106,0,989,21101,0,439,1,1105,1,1150,21101,477,0,1,1106,0,1150,21102,1,514,1,21102,1,1149,0,1105,1,579,99,21101,1157,0,0,1106,0,579,204,-2,104,10,99,21207,-3,22,-1,1206,-1,1138,2101,0,-5,1176,2102,1,-4,0,109,-6,2106,0,0,32,5,46,1,3,1,46,1,3,1,46,1,3,1,46,1,3,1,46,1,3,1,40,11,40,1,5,1,44,1,5,1,44,1,5,1,44,1,5,1,44,1,5,1,40,11,40,1,3,1,46,1,3,1,46,1,3,1,46,1,3,9,38,1,11,1,26,1,11,1,11,1,26,1,11,1,11,1,26,1,11,5,7,1,26,1,15,1,7,1,26,1,15,1,7,1,26,1,15,1,7,1,26,1,11,7,5,1,26,1,11,1,3,1,1,1,5,1,26,1,9,13,1,1,3,13,10,1,9,1,1,1,3,1,1,1,3,1,1,1,3,1,22,5,5,1,1,13,3,1,26,1,5,1,5,1,1,1,3,1,5,1,26,1,5,1,5,7,5,1,26,1,5,1,7,1,9,1,26,1,5,1,7,1,9,1,26,1,5,1,7,1,9,1,26,1,5,1,7,11,26,1,5,1,34,11,5,1,34,1,15,1,34,1,5,9,1,9,26,1,5,1,7,1,9,1,26,1,5,1,7,1,9,1,26,1,5,1,7,1,9,1,22,11,7,1,9,1,22,1,3,1,13,1,9,1,22,1,3,1,13,1,9,1,22,1,3,1,13,1,9,1,22,1,3,1,13,1,9,1,22,1,3,1,13,1,9,1,22,5,13,11,22'

# Build the ASCII Controller
controller = AsciiController()

# build the computer and attach the screen
compute = ComputeEngine(puzzle_program)
# attach the controls
compute.attach_output_device(controller)
#c.attach_input_device(solver)
compute.run(False, False)

controller.print()

alignment = controller.calculate_alignment_parameters()

controller.print()

print(f"Alignment is : {alignment}")

# ok, so let's setup the computer and try a trial run..
compute = ComputeEngine(puzzle_program)
Exemplo n.º 13
0
                if key in self.display:
                    #print("Looking up!")
                    tile_id = self.display[key]
                    #print(f"tile id is {tile_id}")
                    this_char = character_for_tile(tile_id)
                s += this_char
            print(s)
        print("")


# and run the main code
import sys
sys.path.append("c:\\development\\advent-of-code-2019")
from compute_engine.engine import ComputeEngine

puzzle_program = '1,380,379,385,1008,2559,144748,381,1005,381,12,99,109,2560,1102,1,0,383,1102,1,0,382,20101,0,382,1,21001,383,0,2,21102,37,1,0,1105,1,578,4,382,4,383,204,1,1001,382,1,382,1007,382,40,381,1005,381,22,1001,383,1,383,1007,383,24,381,1005,381,18,1006,385,69,99,104,-1,104,0,4,386,3,384,1007,384,0,381,1005,381,94,107,0,384,381,1005,381,108,1105,1,161,107,1,392,381,1006,381,161,1102,-1,1,384,1106,0,119,1007,392,38,381,1006,381,161,1102,1,1,384,20102,1,392,1,21101,0,22,2,21102,0,1,3,21101,138,0,0,1106,0,549,1,392,384,392,21001,392,0,1,21102,1,22,2,21102,3,1,3,21101,161,0,0,1105,1,549,1101,0,0,384,20001,388,390,1,21001,389,0,2,21101,180,0,0,1105,1,578,1206,1,213,1208,1,2,381,1006,381,205,20001,388,390,1,20102,1,389,2,21101,205,0,0,1106,0,393,1002,390,-1,390,1102,1,1,384,20102,1,388,1,20001,389,391,2,21101,0,228,0,1106,0,578,1206,1,261,1208,1,2,381,1006,381,253,20102,1,388,1,20001,389,391,2,21102,1,253,0,1106,0,393,1002,391,-1,391,1102,1,1,384,1005,384,161,20001,388,390,1,20001,389,391,2,21101,279,0,0,1106,0,578,1206,1,316,1208,1,2,381,1006,381,304,20001,388,390,1,20001,389,391,2,21101,0,304,0,1106,0,393,1002,390,-1,390,1002,391,-1,391,1101,1,0,384,1005,384,161,20102,1,388,1,21001,389,0,2,21101,0,0,3,21101,338,0,0,1106,0,549,1,388,390,388,1,389,391,389,20101,0,388,1,20102,1,389,2,21102,1,4,3,21102,365,1,0,1105,1,549,1007,389,23,381,1005,381,75,104,-1,104,0,104,0,99,0,1,0,0,0,0,0,0,398,18,19,1,1,20,109,3,22101,0,-2,1,22102,1,-1,2,21101,0,0,3,21101,414,0,0,1106,0,549,22102,1,-2,1,22102,1,-1,2,21102,429,1,0,1106,0,601,1201,1,0,435,1,386,0,386,104,-1,104,0,4,386,1001,387,-1,387,1005,387,451,99,109,-3,2106,0,0,109,8,22202,-7,-6,-3,22201,-3,-5,-3,21202,-4,64,-2,2207,-3,-2,381,1005,381,492,21202,-2,-1,-1,22201,-3,-1,-3,2207,-3,-2,381,1006,381,481,21202,-4,8,-2,2207,-3,-2,381,1005,381,518,21202,-2,-1,-1,22201,-3,-1,-3,2207,-3,-2,381,1006,381,507,2207,-3,-4,381,1005,381,540,21202,-4,-1,-1,22201,-3,-1,-3,2207,-3,-4,381,1006,381,529,22102,1,-3,-7,109,-8,2106,0,0,109,4,1202,-2,40,566,201,-3,566,566,101,639,566,566,1201,-1,0,0,204,-3,204,-2,204,-1,109,-4,2106,0,0,109,3,1202,-1,40,593,201,-2,593,593,101,639,593,593,21001,0,0,-2,109,-3,2105,1,0,109,3,22102,24,-2,1,22201,1,-1,1,21101,0,487,2,21101,109,0,3,21102,960,1,4,21101,630,0,0,1106,0,456,21201,1,1599,-2,109,-3,2106,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,0,2,2,2,0,2,2,2,2,0,2,2,2,0,2,0,2,2,0,0,0,2,2,0,2,0,2,2,2,0,2,2,2,2,0,2,0,0,1,1,0,2,2,2,0,2,2,2,2,2,2,2,2,0,2,2,0,0,2,2,0,2,0,2,2,2,2,2,0,2,2,2,2,2,2,2,2,0,1,1,0,2,2,2,0,0,2,2,0,2,2,0,2,2,0,0,0,2,0,0,2,2,2,0,2,0,0,2,0,2,0,0,2,2,2,2,2,0,1,1,0,2,2,2,2,2,2,2,2,2,2,2,0,2,2,0,0,0,2,0,0,0,2,2,2,2,2,0,2,2,2,2,2,2,0,2,2,0,1,1,0,0,0,2,2,0,2,2,0,2,2,2,2,2,2,2,2,0,2,2,0,2,0,2,2,2,2,2,2,2,2,2,2,2,0,0,0,0,1,1,0,2,2,2,2,2,2,2,0,0,2,2,2,2,2,0,2,0,2,2,2,2,0,2,2,2,0,2,2,0,2,2,0,0,0,2,2,0,1,1,0,2,2,2,0,0,2,2,0,0,2,0,2,2,0,2,2,2,2,2,2,2,2,2,2,0,0,2,0,2,2,2,0,0,2,2,2,0,1,1,0,0,2,0,0,2,0,0,2,2,2,2,0,2,2,0,2,2,2,2,2,0,0,2,0,0,2,0,0,2,2,2,2,2,2,0,2,0,1,1,0,2,0,2,0,2,2,2,2,2,2,2,2,0,0,2,2,2,0,2,0,2,2,2,2,2,2,0,2,2,2,2,2,2,2,2,2,0,1,1,0,2,2,2,2,2,0,0,2,2,0,2,2,2,2,2,2,2,0,2,2,2,2,2,2,2,2,2,0,0,2,2,2,2,2,2,0,0,1,1,0,2,0,2,2,2,2,2,0,0,0,0,0,2,0,0,0,2,2,0,0,2,2,2,2,0,2,2,2,0,2,2,0,2,0,2,2,0,1,1,0,0,2,0,2,2,2,2,2,0,2,0,2,0,0,2,0,2,0,2,2,0,2,0,2,2,2,2,0,2,0,2,2,0,0,2,2,0,1,1,0,0,2,2,2,0,2,0,2,2,0,2,2,2,0,2,0,0,0,0,0,0,0,2,2,2,0,2,2,2,2,2,0,0,2,2,0,0,1,1,0,2,2,0,2,2,2,2,0,2,0,2,2,2,0,0,0,2,0,0,2,2,2,2,2,0,2,0,2,2,2,0,2,0,0,2,2,0,1,1,0,2,2,2,2,2,2,2,0,2,2,0,2,2,2,0,2,2,2,0,0,0,2,0,0,0,2,2,2,2,2,2,0,2,0,2,2,0,1,1,0,0,2,2,2,2,0,2,2,2,2,2,0,2,2,2,2,2,2,2,2,2,2,2,2,0,2,0,0,2,2,2,2,0,2,2,2,0,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,4,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,3,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,49,65,14,21,97,84,49,78,48,36,96,71,85,76,47,17,61,37,11,13,78,58,57,46,36,71,62,73,93,82,59,40,49,77,56,36,73,64,3,63,79,92,97,57,43,45,31,95,61,73,77,18,60,15,16,78,53,2,62,49,39,51,33,51,87,69,80,9,15,94,96,65,91,16,81,7,97,80,86,42,47,9,66,75,17,74,16,63,8,14,82,46,50,10,2,61,54,14,75,63,4,20,94,43,21,82,15,13,91,7,80,71,5,57,54,6,69,55,4,45,21,94,71,48,73,67,43,25,16,62,14,14,83,36,7,52,62,56,95,54,82,21,55,33,30,22,63,47,76,17,29,6,42,57,58,58,3,8,10,6,82,73,7,42,19,36,47,50,29,76,72,75,76,89,40,24,38,28,13,56,36,60,17,46,11,95,35,34,78,29,80,59,6,17,12,79,48,59,19,64,53,63,8,2,87,78,49,61,5,62,23,4,16,75,13,85,15,70,5,59,38,77,89,39,30,88,9,20,51,66,28,15,24,22,5,87,98,70,12,28,9,20,70,25,10,17,86,19,17,53,55,43,6,23,79,75,67,91,96,42,63,36,59,90,17,20,58,87,69,37,75,22,81,15,41,57,52,55,54,77,71,40,64,7,63,80,23,70,66,59,26,92,94,33,26,50,61,26,63,94,44,45,41,18,81,50,83,77,56,26,79,4,19,92,9,73,72,71,17,30,46,80,69,22,24,23,84,45,91,18,82,46,59,41,76,11,4,62,95,1,22,45,15,62,35,79,82,92,1,19,48,92,97,71,16,7,74,78,88,46,97,67,97,71,54,91,70,65,86,19,85,76,44,69,69,30,18,98,95,28,40,93,85,42,47,56,21,65,70,15,5,24,22,36,10,32,92,48,26,56,81,2,85,29,37,97,25,54,11,40,64,89,58,92,64,69,28,8,53,65,23,46,26,43,90,73,5,50,17,45,2,67,60,82,43,24,73,65,85,57,55,15,26,46,71,58,5,25,58,72,38,75,4,88,73,88,69,76,17,62,47,60,26,68,6,48,70,33,61,53,44,15,95,18,12,50,10,54,47,17,17,5,78,49,16,34,3,26,4,67,67,8,92,46,1,3,72,31,5,52,51,29,8,32,39,88,53,40,86,79,6,91,49,56,17,48,41,86,93,8,2,78,67,1,19,98,88,69,12,49,34,92,77,11,1,36,15,68,60,38,40,44,66,87,33,41,39,81,25,58,17,17,23,3,45,28,18,11,70,33,44,83,84,59,45,41,61,83,82,18,27,23,4,14,43,37,66,16,8,10,90,7,83,94,78,25,36,23,90,95,78,72,8,47,32,29,62,31,89,30,1,40,39,24,50,61,23,36,74,63,42,50,73,13,43,60,89,58,76,35,1,85,47,38,76,21,49,45,9,48,23,54,68,56,84,32,10,49,80,24,57,50,13,85,23,56,28,7,71,91,54,65,7,41,53,68,30,2,35,33,13,1,51,72,30,27,2,80,98,16,89,47,89,41,9,38,51,54,30,41,15,17,35,31,25,64,92,12,34,88,40,78,49,39,2,57,43,30,24,27,34,40,22,76,81,20,39,93,40,44,59,13,3,38,59,25,4,48,77,35,64,12,79,22,84,82,49,69,35,92,95,23,37,45,11,53,2,15,22,65,26,23,92,44,22,64,76,9,27,41,1,12,92,15,14,21,7,26,26,71,11,20,38,87,21,97,97,61,74,31,40,57,55,24,95,2,64,38,41,20,87,11,51,19,72,62,75,66,85,49,70,34,31,74,12,31,93,42,95,31,70,1,68,13,9,3,19,86,21,8,86,81,61,79,47,41,50,23,82,21,16,67,21,21,80,58,75,76,59,50,32,21,72,98,66,9,33,64,61,98,45,73,62,28,84,91,8,23,12,43,79,34,18,27,24,36,92,89,59,57,52,37,20,36,66,8,9,86,31,30,20,96,72,7,19,91,75,17,90,38,72,78,67,4,41,32,88,21,2,44,76,21,82,91,78,64,32,72,91,15,43,18,73,42,47,95,8,19,90,66,10,49,66,58,11,88,48,25,34,51,97,49,2,59,19,17,44,84,83,6,41,27,19,66,19,4,84,17,43,13,41,19,16,87,1,14,40,7,96,53,48,31,67,88,34,55,97,63,15,65,144748'

# build a screen
arcade = ArcadeMachine()

# build the computer and attach the screen
c = ComputeEngine(puzzle_program)
# insert a coin
c.poke(0, 2)
# attach the controls
c.attach_output_device(arcade)
c.attach_input_device(arcade)
c.run(False, False)

arcade.print_display()
Exemplo n.º 14
0
from compute_engine.engine import ComputeEngine

puzzle_program = '109,424,203,1,21101,0,11,0,1105,1,282,21101,18,0,0,1105,1,259,1202,1,1,221,203,1,21102,1,31,0,1106,0,282,21102,38,1,0,1106,0,259,21002,23,1,2,22102,1,1,3,21102,1,1,1,21102,1,57,0,1105,1,303,2102,1,1,222,20101,0,221,3,21001,221,0,2,21102,259,1,1,21102,1,80,0,1106,0,225,21102,62,1,2,21101,91,0,0,1105,1,303,2101,0,1,223,21001,222,0,4,21101,0,259,3,21101,0,225,2,21101,0,225,1,21101,0,118,0,1105,1,225,20102,1,222,3,21101,94,0,2,21102,133,1,0,1105,1,303,21202,1,-1,1,22001,223,1,1,21101,0,148,0,1105,1,259,1202,1,1,223,20101,0,221,4,21001,222,0,3,21102,17,1,2,1001,132,-2,224,1002,224,2,224,1001,224,3,224,1002,132,-1,132,1,224,132,224,21001,224,1,1,21101,195,0,0,105,1,109,20207,1,223,2,20101,0,23,1,21102,-1,1,3,21101,214,0,0,1106,0,303,22101,1,1,1,204,1,99,0,0,0,0,109,5,2101,0,-4,249,22102,1,-3,1,22101,0,-2,2,21201,-1,0,3,21102,1,250,0,1106,0,225,22101,0,1,-4,109,-5,2105,1,0,109,3,22107,0,-2,-1,21202,-1,2,-1,21201,-1,-1,-1,22202,-1,-2,-2,109,-3,2106,0,0,109,3,21207,-2,0,-1,1206,-1,294,104,0,99,22101,0,-2,-2,109,-3,2106,0,0,109,5,22207,-3,-4,-1,1206,-1,346,22201,-4,-3,-4,21202,-3,-1,-1,22201,-4,-1,2,21202,2,-1,-1,22201,-4,-1,1,21201,-2,0,3,21101,343,0,0,1106,0,303,1105,1,415,22207,-2,-3,-1,1206,-1,387,22201,-3,-2,-3,21202,-2,-1,-1,22201,-3,-1,3,21202,3,-1,-1,22201,-3,-1,2,22102,1,-4,1,21102,384,1,0,1105,1,303,1105,1,415,21202,-4,-1,-4,22201,-4,-3,-4,22202,-3,-2,-2,22202,-2,-4,-4,22202,-3,-2,-3,21202,-4,-1,-2,22201,-3,-2,1,21201,1,0,-4,109,-5,2105,1,0'

# build a solver
widths = dict()

total = 0
for y in range(365, 1500):
    s = ''
    start_x = None
    stop_x = None
    solid_total = 0
    for x in range(y, y + 500):
        input = [x, y]
        c = ComputeEngine(puzzle_program)
        c.add_data(input)
        c.run(False, False)
        #print(f"Produced: {c.get_output()}")
        result = c.get_output(0)
        if 1 == result:
            if start_x is None:
                start_x = x
        else:
            if stop_x is None and start_x is not None:
                stop_x = x - 1  # the last digit is behind us..
                solid_total = stop_x - start_x
                break
    print(f"y:{y} solid from {start_x} - {stop_x} for {solid_total}")
    widths[y] = (start_x, stop_x)
    # ok, so the question is, does a grid of 100x100 starting in this row fit into the rows above ?
Exemplo n.º 15
0
#  109,1,204,-1,1001,100,1,100,1008,100,16,101,1006,101,0,99 takes no input
#  and produces a copy of itself as output.
#  1102,34915192,34915192,7,4,7,99,0 should output a 16-digit number.
#  104,1125899906842624,99 should output the large number in the middle.
#  The BOOST program will ask for a single input; run it in test mode by
#  providing it the value 1. It will perform a series of checks on each opcode,
#  output any opcodes (and the associated parameter modes) that seem to be
#  functioning incorrectly, and finally output a BOOST keycode.
#
#  Once your Intcode computer is fully functional, the BOOST program should
#  report no malfunctioning opcodes when run in test mode; it should only
#  output a single value, the BOOST keycode.
#
#  What BOOST keycode does it produce?
#

# sys.path.append("c:\\development\\advent-of-code-2019")
from compute_engine.engine import ComputeEngine

test_copy_self = "109,1,204,-1,1001,100,1,100,1008,100,16,101,1006,101,0,99"
test_16_digits = "1102,34915192,34915192,7,4,7,99,0"
test_large_number = "104,1125899906842624,99"

puzzle_input = "1102,34463338,34463338,63,1007,63,34463338,63,1005,63,53,1101,3,0,1000,109,988,209,12,9,1000,209,6,209,3,203,0,1008,1000,1,63,1005,63,65,1008,1000,2,63,1005,63,904,1008,1000,0,63,1005,63,58,4,25,104,0,99,4,0,104,0,99,4,17,104,0,99,0,0,1102,35,1,1010,1102,1,33,1013,1101,0,715,1022,1102,1,20,1004,1102,1,24,1012,1101,36,0,1005,1101,0,655,1024,1102,32,1,1014,1101,0,499,1026,1102,1,242,1029,1101,0,25,1002,1101,0,27,1017,1101,708,0,1023,1101,0,21,1016,1101,0,28,1000,1101,0,492,1027,1102,34,1,1015,1102,29,1,1007,1102,247,1,1028,1101,0,39,1011,1102,1,31,1018,1102,1,0,1020,1102,1,37,1006,1101,1,0,1021,1102,26,1,1009,1102,1,38,1008,1101,30,0,1019,1102,1,23,1001,1102,650,1,1025,1101,22,0,1003,109,7,2101,0,-7,63,1008,63,29,63,1005,63,205,1001,64,1,64,1105,1,207,4,187,1002,64,2,64,109,-1,1202,-1,1,63,1008,63,35,63,1005,63,227,1106,0,233,4,213,1001,64,1,64,1002,64,2,64,109,17,2106,0,5,4,239,1105,1,251,1001,64,1,64,1002,64,2,64,109,-1,21108,40,39,-4,1005,1018,271,1001,64,1,64,1106,0,273,4,257,1002,64,2,64,109,-9,1206,8,285,1106,0,291,4,279,1001,64,1,64,1002,64,2,64,109,-13,2108,27,0,63,1005,63,307,1106,0,313,4,297,1001,64,1,64,1002,64,2,64,109,11,2101,0,-5,63,1008,63,37,63,1005,63,339,4,319,1001,64,1,64,1105,1,339,1002,64,2,64,109,13,21101,41,0,-9,1008,1015,41,63,1005,63,365,4,345,1001,64,1,64,1106,0,365,1002,64,2,64,109,-14,1201,-6,0,63,1008,63,22,63,1005,63,385,1106,0,391,4,371,1001,64,1,64,1002,64,2,64,109,-10,1202,3,1,63,1008,63,22,63,1005,63,417,4,397,1001,64,1,64,1105,1,417,1002,64,2,64,109,6,1207,-3,21,63,1005,63,437,1001,64,1,64,1105,1,439,4,423,1002,64,2,64,109,16,21107,42,41,-8,1005,1014,455,1105,1,461,4,445,1001,64,1,64,1002,64,2,64,109,-28,2107,24,7,63,1005,63,481,1001,64,1,64,1106,0,483,4,467,1002,64,2,64,109,33,2106,0,0,1001,64,1,64,1106,0,501,4,489,1002,64,2,64,109,-18,2108,38,-1,63,1005,63,519,4,507,1105,1,523,1001,64,1,64,1002,64,2,64,109,-3,1208,-4,25,63,1005,63,545,4,529,1001,64,1,64,1106,0,545,1002,64,2,64,109,12,21102,43,1,-8,1008,1010,43,63,1005,63,571,4,551,1001,64,1,64,1106,0,571,1002,64,2,64,109,-1,1207,-8,27,63,1005,63,593,4,577,1001,64,1,64,1106,0,593,1002,64,2,64,109,-7,21101,44,0,8,1008,1018,42,63,1005,63,617,1001,64,1,64,1105,1,619,4,599,1002,64,2,64,109,-4,1208,-1,39,63,1005,63,639,1001,64,1,64,1105,1,641,4,625,1002,64,2,64,109,13,2105,1,5,4,647,1106,0,659,1001,64,1,64,1002,64,2,64,109,4,1206,-3,673,4,665,1106,0,677,1001,64,1,64,1002,64,2,64,109,-22,21108,45,45,10,1005,1011,699,4,683,1001,64,1,64,1105,1,699,1002,64,2,64,109,29,2105,1,-7,1001,64,1,64,1105,1,717,4,705,1002,64,2,64,109,-19,21107,46,47,5,1005,1016,739,4,723,1001,64,1,64,1106,0,739,1002,64,2,64,109,-8,2102,1,2,63,1008,63,33,63,1005,63,763,1001,64,1,64,1106,0,765,4,745,1002,64,2,64,109,1,1201,-2,0,63,1008,63,25,63,1005,63,791,4,771,1001,64,1,64,1105,1,791,1002,64,2,64,109,16,1205,0,803,1105,1,809,4,797,1001,64,1,64,1002,64,2,64,109,-8,1205,9,827,4,815,1001,64,1,64,1106,0,827,1002,64,2,64,109,-4,2102,1,-3,63,1008,63,36,63,1005,63,853,4,833,1001,64,1,64,1106,0,853,1002,64,2,64,109,17,21102,47,1,-6,1008,1019,50,63,1005,63,877,1001,64,1,64,1105,1,879,4,859,1002,64,2,64,109,-29,2107,22,5,63,1005,63,897,4,885,1106,0,901,1001,64,1,64,4,64,99,21102,27,1,1,21101,0,915,0,1106,0,922,21201,1,25338,1,204,1,99,109,3,1207,-2,3,63,1005,63,964,21201,-2,-1,1,21101,942,0,0,1105,1,922,22102,1,1,-1,21201,-2,-3,1,21102,957,1,0,1106,0,922,22201,1,-1,-2,1105,1,968,21202,-2,1,-2,109,-3,2106,0,0"

c = ComputeEngine()
c.load_memory(puzzle_input)
c.load_data([1])
c.run(False)
c.dump_memory()
Exemplo n.º 16
0
                this_char = '?'
                if key in self.display:
                    #print("Looking up!")
                    tile_id = self.display[key]
                    #print(f"tile id is {tile_id}")
                    this_char = character_for_tile(tile_id)
                s += this_char
            print(s)
        print("")

# and run the main code 
import sys 
sys.path.append("c:\\development\\advent-of-code-2019")
from compute_engine.engine import ComputeEngine


puzzle_program = '1,380,379,385,1008,2559,144748,381,1005,381,12,99,109,2560,1102,1,0,383,1102,1,0,382,20101,0,382,1,21001,383,0,2,21102,37,1,0,1105,1,578,4,382,4,383,204,1,1001,382,1,382,1007,382,40,381,1005,381,22,1001,383,1,383,1007,383,24,381,1005,381,18,1006,385,69,99,104,-1,104,0,4,386,3,384,1007,384,0,381,1005,381,94,107,0,384,381,1005,381,108,1105,1,161,107,1,392,381,1006,381,161,1102,-1,1,384,1106,0,119,1007,392,38,381,1006,381,161,1102,1,1,384,20102,1,392,1,21101,0,22,2,21102,0,1,3,21101,138,0,0,1106,0,549,1,392,384,392,21001,392,0,1,21102,1,22,2,21102,3,1,3,21101,161,0,0,1105,1,549,1101,0,0,384,20001,388,390,1,21001,389,0,2,21101,180,0,0,1105,1,578,1206,1,213,1208,1,2,381,1006,381,205,20001,388,390,1,20102,1,389,2,21101,205,0,0,1106,0,393,1002,390,-1,390,1102,1,1,384,20102,1,388,1,20001,389,391,2,21101,0,228,0,1106,0,578,1206,1,261,1208,1,2,381,1006,381,253,20102,1,388,1,20001,389,391,2,21102,1,253,0,1106,0,393,1002,391,-1,391,1102,1,1,384,1005,384,161,20001,388,390,1,20001,389,391,2,21101,279,0,0,1106,0,578,1206,1,316,1208,1,2,381,1006,381,304,20001,388,390,1,20001,389,391,2,21101,0,304,0,1106,0,393,1002,390,-1,390,1002,391,-1,391,1101,1,0,384,1005,384,161,20102,1,388,1,21001,389,0,2,21101,0,0,3,21101,338,0,0,1106,0,549,1,388,390,388,1,389,391,389,20101,0,388,1,20102,1,389,2,21102,1,4,3,21102,365,1,0,1105,1,549,1007,389,23,381,1005,381,75,104,-1,104,0,104,0,99,0,1,0,0,0,0,0,0,398,18,19,1,1,20,109,3,22101,0,-2,1,22102,1,-1,2,21101,0,0,3,21101,414,0,0,1106,0,549,22102,1,-2,1,22102,1,-1,2,21102,429,1,0,1106,0,601,1201,1,0,435,1,386,0,386,104,-1,104,0,4,386,1001,387,-1,387,1005,387,451,99,109,-3,2106,0,0,109,8,22202,-7,-6,-3,22201,-3,-5,-3,21202,-4,64,-2,2207,-3,-2,381,1005,381,492,21202,-2,-1,-1,22201,-3,-1,-3,2207,-3,-2,381,1006,381,481,21202,-4,8,-2,2207,-3,-2,381,1005,381,518,21202,-2,-1,-1,22201,-3,-1,-3,2207,-3,-2,381,1006,381,507,2207,-3,-4,381,1005,381,540,21202,-4,-1,-1,22201,-3,-1,-3,2207,-3,-4,381,1006,381,529,22102,1,-3,-7,109,-8,2106,0,0,109,4,1202,-2,40,566,201,-3,566,566,101,639,566,566,1201,-1,0,0,204,-3,204,-2,204,-1,109,-4,2106,0,0,109,3,1202,-1,40,593,201,-2,593,593,101,639,593,593,21001,0,0,-2,109,-3,2105,1,0,109,3,22102,24,-2,1,22201,1,-1,1,21101,0,487,2,21101,109,0,3,21102,960,1,4,21101,630,0,0,1106,0,456,21201,1,1599,-2,109,-3,2106,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,0,2,2,2,0,2,2,2,2,0,2,2,2,0,2,0,2,2,0,0,0,2,2,0,2,0,2,2,2,0,2,2,2,2,0,2,0,0,1,1,0,2,2,2,0,2,2,2,2,2,2,2,2,0,2,2,0,0,2,2,0,2,0,2,2,2,2,2,0,2,2,2,2,2,2,2,2,0,1,1,0,2,2,2,0,0,2,2,0,2,2,0,2,2,0,0,0,2,0,0,2,2,2,0,2,0,0,2,0,2,0,0,2,2,2,2,2,0,1,1,0,2,2,2,2,2,2,2,2,2,2,2,0,2,2,0,0,0,2,0,0,0,2,2,2,2,2,0,2,2,2,2,2,2,0,2,2,0,1,1,0,0,0,2,2,0,2,2,0,2,2,2,2,2,2,2,2,0,2,2,0,2,0,2,2,2,2,2,2,2,2,2,2,2,0,0,0,0,1,1,0,2,2,2,2,2,2,2,0,0,2,2,2,2,2,0,2,0,2,2,2,2,0,2,2,2,0,2,2,0,2,2,0,0,0,2,2,0,1,1,0,2,2,2,0,0,2,2,0,0,2,0,2,2,0,2,2,2,2,2,2,2,2,2,2,0,0,2,0,2,2,2,0,0,2,2,2,0,1,1,0,0,2,0,0,2,0,0,2,2,2,2,0,2,2,0,2,2,2,2,2,0,0,2,0,0,2,0,0,2,2,2,2,2,2,0,2,0,1,1,0,2,0,2,0,2,2,2,2,2,2,2,2,0,0,2,2,2,0,2,0,2,2,2,2,2,2,0,2,2,2,2,2,2,2,2,2,0,1,1,0,2,2,2,2,2,0,0,2,2,0,2,2,2,2,2,2,2,0,2,2,2,2,2,2,2,2,2,0,0,2,2,2,2,2,2,0,0,1,1,0,2,0,2,2,2,2,2,0,0,0,0,0,2,0,0,0,2,2,0,0,2,2,2,2,0,2,2,2,0,2,2,0,2,0,2,2,0,1,1,0,0,2,0,2,2,2,2,2,0,2,0,2,0,0,2,0,2,0,2,2,0,2,0,2,2,2,2,0,2,0,2,2,0,0,2,2,0,1,1,0,0,2,2,2,0,2,0,2,2,0,2,2,2,0,2,0,0,0,0,0,0,0,2,2,2,0,2,2,2,2,2,0,0,2,2,0,0,1,1,0,2,2,0,2,2,2,2,0,2,0,2,2,2,0,0,0,2,0,0,2,2,2,2,2,0,2,0,2,2,2,0,2,0,0,2,2,0,1,1,0,2,2,2,2,2,2,2,0,2,2,0,2,2,2,0,2,2,2,0,0,0,2,0,0,0,2,2,2,2,2,2,0,2,0,2,2,0,1,1,0,0,2,2,2,2,0,2,2,2,2,2,0,2,2,2,2,2,2,2,2,2,2,2,2,0,2,0,0,2,2,2,2,0,2,2,2,0,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,4,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,3,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,49,65,14,21,97,84,49,78,48,36,96,71,85,76,47,17,61,37,11,13,78,58,57,46,36,71,62,73,93,82,59,40,49,77,56,36,73,64,3,63,79,92,97,57,43,45,31,95,61,73,77,18,60,15,16,78,53,2,62,49,39,51,33,51,87,69,80,9,15,94,96,65,91,16,81,7,97,80,86,42,47,9,66,75,17,74,16,63,8,14,82,46,50,10,2,61,54,14,75,63,4,20,94,43,21,82,15,13,91,7,80,71,5,57,54,6,69,55,4,45,21,94,71,48,73,67,43,25,16,62,14,14,83,36,7,52,62,56,95,54,82,21,55,33,30,22,63,47,76,17,29,6,42,57,58,58,3,8,10,6,82,73,7,42,19,36,47,50,29,76,72,75,76,89,40,24,38,28,13,56,36,60,17,46,11,95,35,34,78,29,80,59,6,17,12,79,48,59,19,64,53,63,8,2,87,78,49,61,5,62,23,4,16,75,13,85,15,70,5,59,38,77,89,39,30,88,9,20,51,66,28,15,24,22,5,87,98,70,12,28,9,20,70,25,10,17,86,19,17,53,55,43,6,23,79,75,67,91,96,42,63,36,59,90,17,20,58,87,69,37,75,22,81,15,41,57,52,55,54,77,71,40,64,7,63,80,23,70,66,59,26,92,94,33,26,50,61,26,63,94,44,45,41,18,81,50,83,77,56,26,79,4,19,92,9,73,72,71,17,30,46,80,69,22,24,23,84,45,91,18,82,46,59,41,76,11,4,62,95,1,22,45,15,62,35,79,82,92,1,19,48,92,97,71,16,7,74,78,88,46,97,67,97,71,54,91,70,65,86,19,85,76,44,69,69,30,18,98,95,28,40,93,85,42,47,56,21,65,70,15,5,24,22,36,10,32,92,48,26,56,81,2,85,29,37,97,25,54,11,40,64,89,58,92,64,69,28,8,53,65,23,46,26,43,90,73,5,50,17,45,2,67,60,82,43,24,73,65,85,57,55,15,26,46,71,58,5,25,58,72,38,75,4,88,73,88,69,76,17,62,47,60,26,68,6,48,70,33,61,53,44,15,95,18,12,50,10,54,47,17,17,5,78,49,16,34,3,26,4,67,67,8,92,46,1,3,72,31,5,52,51,29,8,32,39,88,53,40,86,79,6,91,49,56,17,48,41,86,93,8,2,78,67,1,19,98,88,69,12,49,34,92,77,11,1,36,15,68,60,38,40,44,66,87,33,41,39,81,25,58,17,17,23,3,45,28,18,11,70,33,44,83,84,59,45,41,61,83,82,18,27,23,4,14,43,37,66,16,8,10,90,7,83,94,78,25,36,23,90,95,78,72,8,47,32,29,62,31,89,30,1,40,39,24,50,61,23,36,74,63,42,50,73,13,43,60,89,58,76,35,1,85,47,38,76,21,49,45,9,48,23,54,68,56,84,32,10,49,80,24,57,50,13,85,23,56,28,7,71,91,54,65,7,41,53,68,30,2,35,33,13,1,51,72,30,27,2,80,98,16,89,47,89,41,9,38,51,54,30,41,15,17,35,31,25,64,92,12,34,88,40,78,49,39,2,57,43,30,24,27,34,40,22,76,81,20,39,93,40,44,59,13,3,38,59,25,4,48,77,35,64,12,79,22,84,82,49,69,35,92,95,23,37,45,11,53,2,15,22,65,26,23,92,44,22,64,76,9,27,41,1,12,92,15,14,21,7,26,26,71,11,20,38,87,21,97,97,61,74,31,40,57,55,24,95,2,64,38,41,20,87,11,51,19,72,62,75,66,85,49,70,34,31,74,12,31,93,42,95,31,70,1,68,13,9,3,19,86,21,8,86,81,61,79,47,41,50,23,82,21,16,67,21,21,80,58,75,76,59,50,32,21,72,98,66,9,33,64,61,98,45,73,62,28,84,91,8,23,12,43,79,34,18,27,24,36,92,89,59,57,52,37,20,36,66,8,9,86,31,30,20,96,72,7,19,91,75,17,90,38,72,78,67,4,41,32,88,21,2,44,76,21,82,91,78,64,32,72,91,15,43,18,73,42,47,95,8,19,90,66,10,49,66,58,11,88,48,25,34,51,97,49,2,59,19,17,44,84,83,6,41,27,19,66,19,4,84,17,43,13,41,19,16,87,1,14,40,7,96,53,48,31,67,88,34,55,97,63,15,65,144748'

# build a screen 
screen = VideoGameScreen()

# build the computer and attach the screen
c = ComputeEngine(puzzle_program)
c.attach_output_device(screen)
c.run(False, False)

screen.print_display()
tile_count = screen.count_tiles(BLOCK_TILE)
print(f"Block tiles count is {tile_count}")