def __init__(self): self.m = np.array([["." for x in range(0, 13)] for y in range(0, 13)]) self.startPos = (6, 6) self.pos = self.startPos cmds = self.loadCmdHistory() self.cpm = cmp.loadFromFile("puzzle25.txt") self.cpm.addInputs([ord(x) for x in cmds]) self.cpm.run()
def __init__(self, coin=-1): self.grid = np.zeros((26, 46)) self.prog = cmp.loadFromFile("puzzle13.txt") self.score = 0 self.ballPos = [-1, -1] self.prevBallPos = [-1, -1] self.paddlePos = [-1, -1] self.forecastBallsX = -1 #Posizione prevista palla sulla linea del pad if coin != -1: self.prog.writeTo(0, coin)
def __init__(self): self.prog = cmp.loadFromFile("puzzle21.txt")
def printGrid(grid): for row in grid: print(''.join(map(str, [int(x) for x in row]))) def getCount(grid): cond = lambda x: x == 1 return sum(partial for partial in (sum(cond(el) for el in grid))) MAX = 50 OFSX = 0 OFSY = 0 prog = cmp.loadFromFile("puzzle19.txt") grid = np.zeros((MAX, MAX)) for y in range(0, grid.shape[0]): for x in range(0, grid.shape[1]): prog.addInput(x + OFSX) prog.addInput(y + OFSY) prog.run() grid[(y, x)] = prog.getOutput(True) prog.reset() printGrid(grid) print("1---->" + str(getCount(grid))) #147
# -*- coding: utf-8 -*- """ Created on Tue Mar 3 11:36:27 2020 @author: stefano """ import intcomputer as cmp cpm = cmp.loadFromFile("puzzle25.txt") while True: cpm.run() out = cpm.getOutputs() print(''.join(out)) inp = input("--->") if inp=="bye": break if not(inp=="north" or inp=="south" or inp=="east" or inp=="west" or inp=="take" or inp=="drop" or inp=="inv"): print("Comando non riconosciuto") inp = list(inp) inp.append(10) cpm.addInputs(list(inp))
def reset(self): self.position = (int(self.size/2), int(self.size/2)) self.prog = cmp.loadFromFile("puzzle15.txt", [])
def __init__(self, size=100): self.size = size self.grid = np.zeros((self.size,self.size), dtype=int) self.position = (int(self.size/2), int(self.size/2)) self.grid[self.position] = self.CURSOR self.prog = cmp.loadFromFile("puzzle15.txt", [])
If a packet would be sent to address 255, the NAT receives it instead. The NAT remembers only the last packet it receives; that is, the data in each packet it receives overwrites the NAT's packet memory with the new packet's X and Y values. The NAT also monitors all computers on the network. If all computers have empty incoming packet queues and are continuously trying to receive packets without sending packets, the network is considered idle. Once the network is idle, the NAT sends only the last packet it received to address 0; this will cause the computers on the network to resume activity. In this way, the NAT can throttle power consumption of the network when the ship needs power in other areas. Monitor packets released to the computer at address 0 by the NAT. What is the first Y value delivered by the NAT to the computer at address 0 twice in a row? Your puzzle answer was 16150.o """ import intcomputer as cmp import numpy as np N = 50 cmps = [cmp.loadFromFile("puzzle23.txt", str(i), [i]) for i in range(0, N)] natX, natY = None, None natY0 = None stop = False idle = False first = True k = 0 while not stop: k += 1 for i in range(0, N): cmps[i].run() idle = True
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? ------------------------------------ Part 2: The program runs in sensor boost mode by providing the input instruction the value 2. Once run, it will boost the sensors automatically, but it might take a few seconds to complete the operation on slower hardware. In sensor boost mode, the program will output a single value: the coordinates of the distress signal. Run the BOOST program in sensor boost mode. What are the coordinates of the distress signal? """ #Test progStr = "109,1,204,-1,1001,100,1,100,1008,100,16,101,1006,101,0,99" prog = cmp.Program(progStr) prog.run(debug=False) out = prog.getOutputs() print("Output: " + str(out)) #copy of itself #Part 1 ---------- prog = cmp.loadFromFile("puzzle09a.txt", inputs=[1]) prog.run(debug=False) out = prog.getOutputs() print("Output: " + str(out)) #3601950151 #Part 2 ---------- prog = cmp.loadFromFile("puzzle09a.txt", inputs=[2]) prog.run(debug=False) out = prog.getOutputs() print("Output: " + str(out)) #64236
def performStep2(self): #Stringa che corrisponde al percorso self.calcPath() m.draw() print("Stringa del percorso: " + self.path) #Trova i pattern ripetuti da assegnare alle movement functions e le ordina per lunghezza decrscente #Forza bruta, prova tutte le combinazioni inStr1 = self.path strs1 = self.findValidSubstrings(inStr1) found = False #Prova tutte le possibili combinazioni di 3 sottostringhe fino a trovare la prima giusta for str1 in strs1: inStr2 = inStr1.replace(str1, " ") strs2 = self.findValidSubstrings(inStr2) for str2 in strs2: inStr3 = inStr2.replace(str2, " ") strs3 = self.findValidSubstrings(inStr3) for str3 in strs3: inStr4 = inStr3.replace(str3, " ") if len(inStr4.strip()) == 0: found = True if found: break if found: break if found: break substrs = [str1, str2, str3] if not found: print("Errore!") substrs = sorted(substrs, reverse=True, key=lambda item: len(item)) print("Movement functions: " + str(substrs)) #Crea una lista con gli indici delle sottostringhe nell'ordine in cui compaiono nelle stringhe (sarà la main movement routine) substrsOrder = [] self.orderSubstrings(self.path, substrs, substrsOrder) #Test della sottostringa: testList = [substrs[i] for i in substrsOrder] testStr = ''.join(map(str, testList)) print("Test: " + str(testStr == self.path)) programs = ["A", "B", "C"] mainMovementRoutine = [programs[i] for i in substrsOrder] print("Main Movement Routine: " + str(mainMovementRoutine)) #Esegue il programma self.prog = cmp.loadFromFile("puzzle17.txt", []) self.prog.program[0] = 2 self.prog.run() self.printOutput() print("Add main movement routine: " + str(mainMovementRoutine)) self.insertInputListToProd(mainMovementRoutine) self.prog.run() for s in substrs: print("Add movement function: " + s) self.insertInputStringToProg(s[:len(s) - 1]) self.prog.run() self.printOutput() print("Add n") self.prog.addInput(ord("n")) self.prog.addInput(10) self.prog.run(False) #Questo visualizza l'eventuale errore self.printOutput(False) return self.prog.getLastOutput()
def __init__(self): self.grid = None self.prog = cmp.loadFromFile("puzzle17.txt", []) self.startPos = (0, 0) self.startDir = self.R