示例#1
0
import sys
sys.path.append('../packages')

from intcode.intcode import Intcode

computer = Intcode()

f = open('input')
programme = f.read()

# even though it hasn;t changed, add the input here so we can time the computer on the console :)
computer.loadProgramme(programme)
computer.setInputMode("internal")
computer.addInput(2)

computer.run()
示例#2
0
computer = Intcode()

f = open('input')
programme = f.read();

computer.loadProgramme(programme)
computer.setOutputMode("saved")
computer.setInputMode("internal")

computer.run()

while computer.hasHalted() == False:
	currentColour = getCurrentPanelColour(currentCoord)

	computer.addInput(currentColour)


	paintPanel(currentCoord, computer.getOutput())
	direction = turn(computer.getOutput())

	currentCoord = move()

minX = min(panels)[0]
maxX = max(panels)[0]
minY = min(panels, key = lambda t: t[1])[1]
maxY = max(panels, key = lambda t: t[1])[1]

# should have flipped the Y, but it is readable!
for y in range(minY, maxY+1):
	for x in range(minX, maxX+1):
示例#3
0
f = open('input')
programme = f.read();


possibleSettings = permutations([0, 1, 2, 3, 4])

maxSignal = 0
maxSettings = ()

for phaseSettings in list(possibleSettings):
	signal = 0

	for phase in phaseSettings:

		computer.loadProgramme(programme)
		computer.addInput(phase)
		computer.addInput(signal)

		computer.setOutputMode("saved")

		computer.run()

		signal = computer.getOutput()

	if signal > maxSignal:
		maxSignal = signal
		maxSettings = phaseSettings

print(maxSignal)
print(maxSettings)