# Run IntCode perm = permutations([5, 6, 7, 8, 9]) maxOutput = 0 for phases in perm: programChain = deepcopy(programChainOrig) output = 0 halt = [False, False, False, False, False] waiting = [False, False, False, False, False] ips = [0, 0, 0, 0, 0] currentProgram = 0 phaseProvided = False while (False in halt): inputPhase = phases[currentProgram] if not (phaseProvided): inputParameters = [inputPhase, output] else: inputParameters = [output] [ programChain[currentProgram], ips[currentProgram], programOutput, halt[currentProgram], waiting[currentProgram] ] = runProgram(programChain[currentProgram], ips[currentProgram], inputParameters, 'Parameter') output = int(programOutput[-1]) currentProgram += 1 if currentProgram == len(programChain): currentProgram = 0 phaseProvided = True if output > maxOutput: maxOutput = output print('Max Output: ' + str(maxOutput))
halt = False areaMap = {} curX = 0 curY = 0 curDir = 1 prevDir = curDir inputParameters = [curDir] locationsVisited = {} repairFound = False locationQueue = queue.Queue() locationQueue.put((curX,curY+1)) while not(halt): [program,ip,relativeBase,outputs,halt,waiting] = runProgram(program,ip,relativeBase,inputParameters,'Parameter',False) if outputs[0] == 0: if curDir == 1: areaMap[(curX,curY+1)] = '#' locationsVisited[(curX,curY+1)] = True #curDir = 4 elif curDir == 2: areaMap[(curX,curY-1)] = '#' locationsVisited[(curX,curY-1)] = True #curDir = 3 elif curDir == 3: areaMap[(curX-1,curY)] = '#' locationsVisited[(curX-1,curY)] = True #curDir = 1 elif curDir == 4:
from IntCode import runProgram # Read IntCode f = open('Day2Input.txt') for line in f: program = line.split(',') program = [int(n) for n in program] f.close() # Run IntCode program = runProgram(program) print(program[0])
from IntCode import runProgram from itertools import permutations from copy import deepcopy # Read IntCode f = open('Day9Input.txt') for line in f: program = line.split(',') program = [int(n) for n in program] f.close() ip = 0 halt = False waiting = True [program,memory,ip,programOutput,halt,waiting] = runProgram(program,ip=0,inputs=[2],inputMode='Parameter',debug=False)
from IntCode import runProgram f = open('Day13Input.txt') for line in f: program = line.strip('\n').split(',') program = [int(n) for n in program] f.close() [program, ip, relativeBase, outputs, halt, waiting] = runProgram(program, 0, 0, [], 'Parameter', False) screen = {} outputCount = 0 curX = 0 curY = 0 curVal = 0 for outputData in outputs: if outputCount == 0: curX = outputData elif outputCount == 1: curY = outputData elif outputCount == 2: curVal = outputData outputCount += 1 if outputCount > 2: screen[(curX, curY)] = curVal outputCount = 0 blockCount = 0 for value in screen.values(): if value == 2: blockCount += 1
# Run Program halt = False waiting = False ip = 0 relativeBase = 0 while not (halt): robotPositionTuple = (robotPosition[0], robotPosition[1]) if robotPositionTuple in paintedPanels.keys(): currentPaintColor = paintedPanels[robotPositionTuple] else: currentPaintColor = 0 #not painted yet so black inputParameters = [currentPaintColor] [program, ip, relativeBase, outputs, halt, waiting] = runProgram(program, ip, relativeBase, inputParameters, 'Parameter', True) paintColor = outputs[0] turnDirection = outputs[1] # paint robotPositionTuple = (robotPosition[0], robotPosition[1]) paintedPanels[robotPositionTuple] = paintColor # turn if turnDirection == 1: # right 90 if robotDirection == [0, 1]: # up robotDirection = [1, 0] # right elif robotDirection == [1, 0]: # right robotDirection = [0, -1] # down elif robotDirection == [0, -1]: # down
from IntCode import runProgram from copy import deepcopy f = open('Day19Input.txt') for line in f: program = line.strip('\n').split(',') program = [int(n) for n in program] f.close() initProgram = deepcopy(program) outputArea = '' pointsAffected = 0 for x in range(0, 50): for y in range(0, 50): inputParameters = [x, y] ip = 0 relativeBase = 0 halt = False while not (halt): [program, ip, relativeBase, outputs, halt, waiting] = runProgram(initProgram, ip, relativeBase, inputParameters, 'Parameter', False) if outputs[0] == 1: outputArea += '#' pointsAffected += 1 else: outputArea += '.' outputArea += '\n' print(pointsAffected)
# Read IntCode f = open('Day7Input.txt') for line in f: program = line.split(',') program = [int(n) for n in program] f.close() ampAProgram = program[:] ampBProgram = program[:] ampCProgram = program[:] ampDProgram = program[:] ampEProgram = program[:] programChainOrig = [ ampAProgram, ampBProgram, ampCProgram, ampDProgram, ampEProgram ] # Run IntCode perm = permutations([0, 1, 2, 3, 4]) maxOutput = 0 for phases in perm: programChain = deepcopy(programChainOrig) output = 0 for i, program in enumerate(programChain): inputPhase = phases[i] [programChain[i], programOutput] = runProgram(programChain[i], [inputPhase, output]) output = int(programOutput[0]) if output > maxOutput: maxOutput = output print('Max Output: ' + str(maxOutput))