示例#1
0
def firstVisiblePoint():
    for i in range(1, 50):
        for j in range(1, 50):
            UserInput.append((i, j))

    for spot in UserInput:
        robot = IntcodeVM(memry.copy())
        robot.updateInput([spot[0], spot[1]])
        robot.run()
        if robot.prgOutput == 1:
            return (spot[0], spot[1])
示例#2
0
def collect_all_items(program, item_paths):
    command_list = []
    for path, item in item_paths:
        if item[0] == "Checkpoint":
            continue
        command_list.extend(path)
        command_list.append(f"take {item}")
        command_list.extend(OPPOSITES[step] for step in reversed(path))
    command_list.extend(next(path for path, item in item_paths if item[0] == "Checkpoint"))
    for _, item in item_paths:
        command_list.append(f"drop {item}")
    vm = IntcodeVM(program, CommandInput(command_list), lambda c: None)
    vm.run()
    return vm
示例#3
0
### (!A && D) || (!B && D) || (!C && D && H)

from intcode import IntcodeVM

file = open('input.txt', 'r')

memry = []

for line in file:
    memry = line.split(',')

robot = IntcodeVM(memry)

UserInput = []
answer = "NOT A T\nNOT B J\nAND D J\nOR T J\nNOT C T\nAND D T\nAND H T\nOR T J\nRUN\n"

for a in answer:
    UserInput.append(ord(a))

robot.updateInput(UserInput)

while robot.finished == False:
    robot.run()
    if robot.prgOutput < 255:
        print(chr(robot.prgOutput), end="")
    else:
        print(robot.prgOutput)
示例#4
0
for line in file:
    memry = line.split(',')

tiles = defaultdict(int)

memry[0] = 2

robot = IntcodeVM(memry)
score = 0
ballPos = (0, 0)
playerPos = (0, 0)
playerInput = 0
frameCounter = 0

while robot.finished == False:
    robot.run(playerInput)
    xpos = robot.prgOutput
    robot.run(playerInput)
    ypos = robot.prgOutput
    robot.run(playerInput)
    tileID = robot.prgOutput
    pos = (xpos, ypos)

    if pos == (-1, 0):
        score = tileID
    else:
        tiles[pos] = tileID
        if tileID == 4:
            ballPos = pos
        if tileID == 3:
            playerPos = pos
示例#5
0
def run(data: Data, stdin: Optional[Data] = None) -> Data:
    vm = IntcodeVM(data, stdin=stdin)
    vm.run()
    return vm.stdout
示例#6
0
from intcode import IntcodeVM
from collections import defaultdict

file = open('input.txt', 'r')

for line in file:
    memry = line.split(',')

robot = IntcodeVM(memry)

nrOfBlockTiles = 0

while robot.finished == False:
    robot.run(137)
    robot.run(137)
    robot.run(137)
    tileID = robot.prgOutput
    if tileID == 2:
        nrOfBlockTiles += 1

print(nrOfBlockTiles)
示例#7
0
                print("@", end="")
            else:
                print("▓", end="")
        print("")


grid = defaultdict(lambda: -1)
robot = IntcodeVM(memry)
startPos = (0, 0)
grid[startPos] = 1
rob = startPos
OXYGEN = (1234, 1234)
facing = 1

while True:
    robot.run(getLeft())
    if robot.prgOutput == 2:  #finished
        rob = positionQueried(getLeft())
        facing = getLeft()
        OXYGEN = rob
        grid[OXYGEN] = 1
        break
    elif robot.prgOutput == 0:
        grid[positionQueried(getLeft())] = 0
        robot.run(facing)
        if robot.prgOutput == 2:  #finished
            rob = positionQueried(facing)
            OXYGEN = rob
            grid[OXYGEN] = 1
            break
        elif robot.prgOutput == 0:
示例#8
0
from collections import defaultdict

file = open('input.txt', 'r')

for line in file:
    memry = line.split(',')

currentLocation = (0, 0)
facing = 0
panels = defaultdict(int)

robot = IntcodeVM(memry)
panels[currentLocation] = 1

while robot.finished == False:
    robot.run(panels[currentLocation])
    colourToPaint = robot.prgOutput
    robot.run(panels[currentLocation])
    turn = robot.prgOutput
    panels[currentLocation] = colourToPaint
    if turn == 0:
        facing -= 1
    if turn == 1:
        facing += 1
    facing = facing % 4
    if facing == 0:
        currentLocation = (currentLocation[0], currentLocation[1] + 1)
    if facing == 1:
        currentLocation = (currentLocation[0] + 1, currentLocation[1])
    if facing == 2:
        currentLocation = (currentLocation[0], currentLocation[1] - 1)
示例#9
0
## Read tries.txt to see me trying all the inputs. Solved today mostly by hand!

from intcode import IntcodeVM

file = open('input.txt', 'r')

memry = []

for line in file:
    memry = line.split(',')

comp = IntcodeVM(memry)

while True:
    comp.run()
    print(chr(comp.prgOutput), end="")
示例#10
0
 def test_part1_example1(self):
     data = decode(
         "109,1,204,-1,1001,100,1,100,1008,100,16,101,1006,101,0,99")
     vm = IntcodeVM(data)
     vm.run()
     self.assertListEqual(vm.stdout, data)
示例#11
0
 def test_part2(self):
     with open_fixture("day09") as fp:
         data = decode(fp.readline())
     vm = IntcodeVM(data, [2])
     vm.run()
     self.assertListEqual(vm.stdout, [49122])
示例#12
0
 def test_part1_example3(self):
     data = decode("104,1125899906842624,99")
     vm = IntcodeVM(data)
     vm.run()
     self.assertEqual(vm.stdout[0], 1125899906842624)
示例#13
0
 def test_part1_example2(self):
     data = decode("1102,34915192,34915192,7,4,7,99,0")
     vm = IntcodeVM(data)
     vm.run()
     self.assertGreaterEqual(vm.stdout[0], 1000000000000000)
示例#14
0
def checkPoint(thisPoint):
    robot = IntcodeVM(memry.copy())
    robot.updateInput([thisPoint[0], thisPoint[1]])
    robot.run()
    return robot.prgOutput