Beispiel #1
0
def solve(d):
    size = 1000
    hit = set()
    extremes = [[0, 0] for _ in range(size)]
    # seen_wide = False
    # wide_width = 200

    for y in range(size):
        for x in range(y, 2 * y):
            computer = Computer(d, x)

            while True:
                retcode, retval = computer.step()

                if retcode == 0 and retval == 3:
                    computer.set_input(y)
                    break

            retcode, retval = computer.get_output()

            if retval == 1:
                # if (y, x - wide_width) in hit:
                #     seen_wide = True
                hit.add((y, x))
                # if seen_wide and (y - 99) in hit:
                if (y - 99, x + 99) in hit:
                    return 10000 * x + y - 99
                if extremes[y][0] == 0:
                    extremes[y][0] = x
                    if (y - 99, x + 99) in hit:
                        print(y, x)
                extremes[y][1] = x

    return len(hit)
Beispiel #2
0
def solve_part(d, noun, verb):
    d[1] = noun
    d[2] = verb

    computer = Computer(d, 0)
    
    while True:
        retcode, retval = computer.get_output()

        if retcode == -1:
            return retval
Beispiel #3
0
def solve(d, inp):
    computer = Computer(d, inp)
    answer = 0

    while True:
        retcode, retval = computer.get_output()

        if retcode == 1:
            answer = retval
        else:
            return answer
def solve(d):
    computer = Computer(d, 0)
    count = 0
    running = 0
    loops = 0

    while running != -1:
        running, retval = computer.get_output()
        if loops % 3 == 2 and retval == 2:
            count += 1
        loops += 1

    return count
def solve(d):
    grid = []
    row = []

    computer = Computer(d, 1)

    while True:
        retcode, retval = computer.get_output()

        if retcode == -1:
            break

        if retval == 10:
            grid.append(row)
            row = []

        else:
            row.append(retval)

    if row:
        grid.append(row)

    score = 0

    if not grid[-1]:
        grid = grid[:-1]

    height = len(grid)
    width = len(grid[0])

    for y in range(height):
        for x in range(width):
            if grid[y][x] == 46:
                continue

            if y == 0 or x == 0 or y == height - 1 or x == width - 1:
                continue

            if grid[y - 1][x] == 46:
                continue
            if grid[y + 1][x] == 46:
                continue
            if grid[y][x - 1] == 46:
                continue
            if grid[y][x + 1] == 46:
                continue

            score += y * x

    return score
Beispiel #6
0
def main():
    with open('data.txt', 'r') as f:
        program = f.read()
    program = [int(i) for i in program.strip().split(',')]
    computer = Computer(program)
    computer.start()
    while True:
        while computer.has_output():
            print(chr(computer.get_output()), end='')
        command = input()
        if command == 'exit':
            break
        command = list(command)
        while command:
            computer.set_input(ord(command.pop(0)))
        computer.set_input(ord('\n'))
    computer.terminate()
def solve(d):
    count = 0

    for x in range(50):
        for y in range(50):
            computer = Computer(d, x)

            while True:
                retcode, retval = computer.step()

                if retcode == 0 and retval == 3:
                    computer.set_input(y)
                    break

            retcode, retval = computer.get_output()

            if retval == 1:
                count += 1

    return count
Beispiel #8
0
def solve(data, inp):
    computer = Computer(data, inp)
    return computer.get_output()[1]
Beispiel #9
0
 def _get_value_from_robot(self, point):
     computer = Computer(self.program)
     computer.start()
     computer.set_input(point.x)
     computer.set_input(point.y)
     return computer.get_output()