コード例 #1
0
def runRobot(instructions):
    robotController = getInputData()
    IC = IntcodeComputer(robotController)
    IC.run_program(instructions)
    outCode = IC._output
    # print(ascii2str(outCode))
    return ascii2str(outCode)
コード例 #2
0
def day05PartOne():
    prg = getInputData()
    IntCode = IntcodeComputer(prg)
    print(
        f'Solution Day 05, Part one:\nRunning TEST diagnostic program...\nGive manual input=>1\n'
    )
    IntCode.run_program()
コード例 #3
0
def day05PartTwo():
    prg2 = getInputData()
    IntCode2 = IntcodeComputer(prg2)
    print(
        f'Solution Day 05, Part two:\nRunning TEST diagnostic program...\nGive manual input=>5\n'
    )
    IntCode2.run_program()
コード例 #4
0
ファイル: solution.py プロジェクト: ccharles/AdventCode
def run_the_magic_program(input_sequence, noun, verb):
    # create a copy of input_sequence to make sure we don't change the
    # original one
    input_sequence_copy = input_sequence.copy()
    input_sequence_copy[1] = noun
    input_sequence_copy[2] = verb

    command_invoker = IntcodeComputer(program=input_sequence_copy)
    command_invoker.run_program()
    return command_invoker.get_memory_state()[0]
コード例 #5
0
ファイル: solution.py プロジェクト: ccharles/AdventCode
def solution():
    from pathlib import Path
    input_file = Path(INPUT_FILE)
    # parse the sequence of commands and put the value as the computer input
    num_sequence = parse_program(input_file)
    computer = IntcodeComputer(program=num_sequence)
    computer.send_input_data(2)
    # set the input value that we want to pass to the Input command
    computer.run_program()
    return computer.output_buffer.value
コード例 #6
0
def solution():
    from pathlib import Path
    input_file = Path(INPUT_FILE)
    # parse the sequence of commands and replace two elements with values
    # according to the task
    num_sequence = parse_program(input_file)
    computer = IntcodeComputer(program=num_sequence)
    # set the input value that we want to pass to the Input command
    computer.send_input_data(5)
    computer.run_program()
    return computer.output_buffer.value
コード例 #7
0
def solution():
    from pathlib import Path
    input_file = Path(INPUT_FILE)
    # parse the sequence of commands and replace two elements with values
    # according to the task
    program = parse_program(input_file)
    program[1] = 12
    program[2] = 2
    # do the calculation
    computer = IntcodeComputer(program=program)
    computer.run_program()
    result = computer.get_memory_state()
    return result[0]
コード例 #8
0
ファイル: day_11.py プロジェクト: thebertster/aoc_2019
def paint_ship(program, start_colour):
    location = (0, 0)
    direction = 0

    panels = {}

    panels[location] = start_colour

    computer = IntcodeComputer(program)

    program_output = computer.run_program()

    while True:
        current_panel = panels.setdefault(location)
        computer.add_input(0 if current_panel is None else current_panel)
        try:
            colour = next(program_output)
            turn = next(program_output)
        except StopIteration:
            break
        panels[location] = colour
        direction = (direction + turn*2 - 1) % 4
        location = (location[0] + DIRECTIONS[direction][0],
                    location[1] + DIRECTIONS[direction][1])

    return panels
コード例 #9
0
ファイル: day_19.py プロジェクト: eriksylvan/AdventOfCode2019
def isInBeam(x, y):
    code = getInputData()
    IC = IntcodeComputer(code)
    o = IC.run_program([x, y])
    if o[0] == 1:
        return True
    else:
        return False
コード例 #10
0
ファイル: day2.py プロジェクト: brianmknapp/AdventOfCode2019
def part_2(input_data, desired_value):
    int_comp = IntcodeComputer(input_data)
    for i in range(100):
        for j in range(100):
            input_data[1] = i
            input_data[2] = j
            output = int_comp.run_program(input_data)
            if output != 4023471:
                print('debug')
            if output == desired_value:
                return 100 * i + j
コード例 #11
0
ファイル: day_19.py プロジェクト: eriksylvan/AdventOfCode2019
def drone(h=50, w=50):
    code = getInputData()
    # IC = IntcodeComputer(code)
    #    out = {}
    pic = []
    count = 0
    for y in range(h):
        row = ''
        for x in range(w):
            IC = IntcodeComputer(code)
            o = IC.run_program([x, y])
            if o[0] == 1:
                count += 1
                row += '#'
            else:
                row += '.'

        pic.append(row)

    # print(out)
    for r in pic:
        print(r)

    return count
コード例 #12
0
ファイル: day_17.py プロジェクト: eriksylvan/AdventOfCode2019
def doTheSpacewalk():
    code = getInputData()
    IC = IntcodeComputer(code)
    IC._intCodeProgramDict[
        0] = 2  # orce the vacuum robot to wake up by changing the value in your ASCII program at address 0 from 1 to 2
    # print(IC._intCodeProgramDict)
    M = 'A,B,A,B,A,C,B,C,A,C\n'
    A = 'L,10,L,12,R,6\n'
    B = 'R,10,L,4,L,4,L,12\n'
    C = 'L,10,R,10,R,6,L,4\n'
    F = 'n\n'  # continuous video feed; provide either y or n and a newline
    Ml = [ord(ch) for ch in M]
    Al = [ord(ch) for ch in A]
    Bl = [ord(ch) for ch in B]
    Cl = [ord(ch) for ch in C]
    Fl = [ord(ch) for ch in F]
    input = Ml + Al + Bl + Cl + Fl
    # print(input)
    output = IC.run_program(input)
    # print(output)
    map = decodeMap(output[:-1])
    printMap(map)
    return output[
        -1]  # amount of space dust it collected as a large, non-ASCII value in a single output instruction.
コード例 #13
0
ファイル: day_07.py プロジェクト: eriksylvan/AdventOfCode2019
def getReturnValue(settingList, amplifierInputCopy):
    print(settingList)
    IntComp = IntcodeComputer(amplifierInputCopy)
    val = IntComp.run_program(settingList)
    return val
コード例 #14
0

def getInputData():
    '''Reads the input file end returns the data in a list of int'''
    data = []
    with open(inputFile) as input:
        for line in input:
            data = [int(x) for x in line.split(',')]
    return data


if __name__ == "__main__":
    prg = getInputData()
    #print(prg)
    IC = IntcodeComputer(prg)
    IC.run_program()
    str = ""
    str = str.join(([chr(ch) for ch in IC._output]))
    print(str)
'''
       .     .                       *** **
                !      .           ._*.                       .
             - -*- -       .-'-.   !  !     .
    .    .      *       .-' .-. '-.!  !             .              .
               ***   .-' .-'   '-. '-.!    .
       *       ***.-' .-'         '-. '-.                   .
       *      ***$*.-'               '-. '-.     *
  *   ***     * ***     ___________     !-..!-.  *     *         *    *
  *   ***    **$** *   !__!__!__!__!    !    !  ***   ***    .   *   ***
 *** ****    * *****   !__!__!__!__!    !      .***-.-*** *     *** * #_
**********  * ****$ *  !__!__!__!__!    !-..--'*****   # '*-..---# ***
コード例 #15
0
ファイル: day_07.py プロジェクト: thebertster/aoc_2019
puzzle = (2019, 7)

# Initialise the helper library

aoc = AOCLib(puzzle[0])

puzzle_input = aoc.get_puzzle_input(puzzle[1], AOCLib.to_list_int)

highest_signal = 0

for phase in permutations(range(5)):
    last_output = 0
    for amp in range(5):
        computer = IntcodeComputer(puzzle_input, phase[amp], last_output)
        last_output = next(computer.run_program())
    if last_output > highest_signal:
        highest_signal = last_output

aoc.print_solution(1, highest_signal)

max_thruster_signal = -1

for phase in permutations(range(5, 10)):
    computers = []
    generators = []
    for amp in range(5):
        computers.append(IntcodeComputer(puzzle_input))
        computers[amp].add_input(phase[amp])
        generators.append(computers[amp].run_program())
    data = 0
コード例 #16
0
ファイル: day_09.py プロジェクト: eriksylvan/AdventOfCode2019
def BOOSTkeycode(intOpPrg, input):
    IntComp = IntcodeComputer(intOpPrg)
    keycode = IntComp.run_program(inp=input)
    return keycode
コード例 #17
0
 def test_example2(self):
     IC = IntcodeComputer([103,7,8,7,8,9,99,-1,8])
     IC.run_program([8])
     self.assertEqual(IC.readMem(7), -1)
     self.assertEqual(IC.readMem(1), 8)
コード例 #18
0
 def test_example1(self):
     IC = IntcodeComputer([3,7,8,7,8,7,99,-1,8])
     IC.run_program([8])
     self.assertEqual(IC.readMem(7), 1)
コード例 #19
0
ファイル: day2.py プロジェクト: brianmknapp/AdventOfCode2019
def part_1(input_data):
    int_comp = IntcodeComputer(input_data)
    input_data[1] = 12
    input_data[2] = 2
    return int_comp.run_program(input_data)
コード例 #20
0
 def runIntCode(self, code, input=[]):
     IntCode = IntcodeComputer(code)
     output = IntCode.run_program(input)
     return output