Пример #1
0
# A = [ord('L'), ord(','), ord('1'), ord('2'), ord(','), ord('R'), ord(','), ord('8'), ord(','), ord('L'), ord(','), ord('6'), ord(','), ord('R'), ord(','), ord('8'), ord(','), ord('L'), ord(','), ord('6'), 10]
# B = [ord('R'), ord(','), ord('8'), ord(','), ord('L'), ord(','), ord('1'), ord('2'), ord(','), ord('L'), ord(','), ord('1'), ord('2'), ord(','), ord('R'), ord(','), ord('8'), 10]
# C = [ord('L'), ord(','), ord('6'), ord(','), ord('R'), ord(','), ord('6'), ord(','), ord('L'), ord(','), ord('1'), ord('2'), 10]

inp = [[]]

done = False
ip = 0
rb = 0

hasPath = False

while not done:
    input = inp.pop(0)

    (done, output, program, ip, rb) = ic.evaluate(program, input, ip, rb)

    map = []

    if done:
        print(output[len(output) - 1])
        break

    row = 0
    map.append([])
    for i in output:
        if i == 10:
            map.append([])
            row += 1
        else:
            map[row].append(chr(i))
Пример #2
0
gameBoard = []
for y in range(0, 20):
    gameBoard.append([])
    for x in range(0, 44):
        gameBoard[y].append(0)

dir = 0
bdx = 1
ballPos = (20,15)
done = False

while not done:
    ip = 0
    rb = 0
    (done, output, program, ip, rb) = ic.evaluate(program, [dir], ip, rb)

    i = 0
    score = 0

    maxX = 0
    maxY = 0

    while i < len(output):
        x = output[i]
        y = output[i + 1]

        if x == -1 and y == 0:
            score = output[i + 2]
            i += 3
            continue
Пример #3
0
def checkSquare(x, y):
    return ic.evaluate(
        orgProg.copy(), [x, y], 0, 0)[1][0] == 1 and ic.evaluate(
            orgProg.copy(), [x + 99, y], 0, 0)[1][0] == 1 and ic.evaluate(
                orgProg.copy(), [x, y + 99], 0, 0)[1][0] == 1 and ic.evaluate(
                    orgProg.copy(), [x + 99, y + 99], 0, 0)[1][0] == 1
Пример #4
0
import sys
import intcode as ic

orgProg = ic.programFromFile(sys.argv[1])

nl = chr(10)

#Part 1
springscript = "NOT C J" + nl + "AND D J" + nl + "NOT A T" + nl + "OR T J" + nl + "WALK" + nl

springscript = [ord(x) for x in springscript]

(done, output, program, ip, rb) = ic.evaluate(orgProg.copy(), springscript, 0, 0)

for i in output:
    if i < 256:
        print chr(i),
    else:
        print(i)

#Part 2
springscript = "NOT C J" + nl + "AND D J" + nl + "AND H J" + nl + "NOT A T" + nl + "OR T J" + nl + "NOT B T" + nl + "AND D T" + nl + "OR T J" + nl + "RUN" + nl

springscript = [ord(x) for x in springscript]

(done, output, program, ip, rb) = ic.evaluate(orgProg.copy(), springscript, 0, 0)

for i in output:
    if i < 256:
        print chr(i),
    else:
Пример #5
0
    return ic.evaluate(
        orgProg.copy(), [x, y], 0, 0)[1][0] == 1 and ic.evaluate(
            orgProg.copy(), [x + 99, y], 0, 0)[1][0] == 1 and ic.evaluate(
                orgProg.copy(), [x, y + 99], 0, 0)[1][0] == 1 and ic.evaluate(
                    orgProg.copy(), [x + 99, y + 99], 0, 0)[1][0] == 1


for i in range(1000, 1500, 1):
    t = [0, searchSize]
    new = t
    found = False
    rowFound = False
    while True:
        #print(new)
        for q in new:
            output = ic.evaluate(orgProg.copy(), [q, i], 0, 0)[1]
            if output[0] == 1:
                found = True
                b = q
                break
        if found:
            break
        new = []
        for j in range(len(t) - 1):
            newNumber = (t[j] + t[j + 1]) // 2
            if newNumber not in t:
                new.append(newNumber)
        if len(new) == 0:
            b = -1
            break
        t = sorted(t + new)