Esempio n. 1
0
def part1(data):
    print(data)

    grid = []
    size = 50
    for j in range(size):
        row = []
        for i in range(size):
            row.append(".")
        grid.append(row)

    for j in range(size):
        for i in range(size):
            print("inputs", i, j)
            # in this problem, the intcoder only runs once for each input
            intcoder = Intcode(deepcopy(data), [i, j], debug=False)
            intcoder.run()
            print("output", intcoder.output)
            if intcoder.output[0] == 1:
                grid[j][i] = "#"

    print_2d_grid(grid)
    count = 0
    for row in grid:
        for item in row:
            if item == "#":
                count += 1

    print("count", count)
Esempio n. 2
0
def part1(data):
    print(data)
    data[1] = 12
    data[2] = 2

    intcoder = Intcode(data)
    intcoder.run()

    print("answer", intcoder.state[0])
Esempio n. 3
0
def part1(data):
    print(data)
    intcoder = Intcode(data, [0])
    intcoder.run()
    output = intcoder.output
    output = chunkIt(output, len(output)/3)
    numBlocks = 0
    for tile in output:
        if tile[2] == 2:
             numBlocks +=1
    print(numBlocks)
Esempio n. 4
0
def part2(data):

    asciiInput = ""

    # PART 1
    # if not (A or B or C) and D then jump
    # J if A is ground
    asciiInput += "NOT A J\n"
    # T if B is ground
    asciiInput += "NOT B T\n"

    # J if A or B is ground
    asciiInput += "OR T J\n"
    # T if C is ground
    asciiInput += "NOT C T\n"
    # J if (A or B or C) is ground
    asciiInput += "OR T J\n"

    # J if (A or B or C) and D is ground
    asciiInput += "AND D J\n"

    # PART 2
    # jump if D and (H or EI or EF)
    #         D and (H or (E and (I or F)))
    # set T = I, T OR F, T AND E, T OR H
    asciiInput += "NOT I T\n"
    asciiInput += "NOT I T\n"
    asciiInput += "OR F T\n"
    asciiInput += "AND E T\n"
    asciiInput += "OR H T\n"
    # huh....
    asciiInput += "OR E T\n"
    asciiInput += "OR H T\n"
    asciiInput += "AND T J\n"

    # final command
    # asciiInput += "WALK\n"
    asciiInput += "RUN\n"

    intcode_input = asciiToIntcodeInput(asciiInput)
    intcoder = Intcode(data, intcode_input)
    intcoder.run()

    # check intocder output
    if len(intcoder.output) > 0:
        if intcoder.output[-1] > 127:
            print("hull damage:", intcoder.output[-1])
        else:
            print("droid fell")
            print_2d_grid(intcodeOutputToAscii(intcoder.output))
            print()
    else:
        print("ERROR: no intcoder output??")
Esempio n. 5
0
def part1(data):
    print(data)

    intcode_input = []
    intcoder = Intcode(data, intcode_input, extra_mem=10000, debug=False)
    intcoder.run()
    output = intcoder.output
    print(output)
    grid = intcodeOutputToAscii(output)
    print_2d_grid(grid)
    intersections = findIntersections(grid)
    print("intersections:", intersections)
    total = 0
    for (x, y) in intersections:
        total += x * y
    print("total", total)
Esempio n. 6
0
def part2(origData):
    print(origData)

    goal = 19690720
    guess = 0
    while guess != goal:
        data = deepcopy(origData)
        data[1] = randint(0, 100)
        data[2] = randint(0, 100)

        intcoder = Intcode(data)
        intcoder.run()

        guess = intcoder.state[0]
        print(guess)
    print("answer", data[1] * 100 + data[2])
Esempio n. 7
0
def part1(data):
    # Get all permutations
    phases = list(permutations([0, 1, 2, 3, 4]))

    largest = -sys.maxsize
    largestphase = []

    # Print the obtained permutations
    for phase in phases:
        ampout = 0
        for ampi in range(0, 5):
            intcoder = Intcode(data.copy(), [phase[ampi], ampout])
            intcoder.run()
            ampout = intcoder.output[0]
        if ampout > largest:
            largest = ampout
            largestphase = phase
    print(largest, "with", largestphase)
Esempio n. 8
0
def part2(data):
    print(data)
    # "Force the vacuum robot to wake up by changing the
    #  value in your ASCII program at address 0 from 1 to 2"
    data[0] = 2

    # found these paths by hand!
    A = ["R", "8", "L", "10", "L", "12", "R", "4"]
    B = ["R", "8", "L", "12", "R", "4", "R", "4"]
    C = ["R", "8", "L", "10", "R", "8"]
    routine = ["A", "B", "A", "C", "A", "B", "C", "B", "C", "B"]

    # convert paths to input
    intcode_input = pathToASCII(routine) + pathToASCII(A) + pathToASCII(
        B) + pathToASCII(C) + [ord("n"), 10]
    print("input", intcode_input)
    # fire it off
    intcoder = Intcode(data, intcode_input, extra_mem=10000, debug=False)
    intcoder.run()
    output = intcoder.output
    print(output[-1])
Esempio n. 9
0
def part2(data):

    print(data)
    i = j = 10
    points = []

    while True:
        # zig zag down the bottom line
        print("inputs", i, j)
        # in this problem, the intcoder only runs once for each input
        intcoder = Intcode(deepcopy(data), [i, j], debug=False)
        intcoder.run()
        print("output", intcoder.output)
        # down if it's a spot, right if not
        if intcoder.output[0] == 1:
            points.append((i, j))
            # if it's a spot, check the upper right corner
            x = i + 99
            y = j - 99
            if y >= 0:
                print("checking upper corner", x, y)
                intcoder = Intcode(deepcopy(data), [x, y], debug=False)
                intcoder.run()
                if intcoder.output[0] == 1:
                    # we good
                    points.append((x, y))
                    # drawPoints(points)
                    # take the upper left corner
                    # x * 10000 + y
                    points.append((i, y))
                    print("answer:", i * 10000 + y)

                    exit(0)
            # go down
            j += 1
        else:
            # go right
            i += 1
Esempio n. 10
0
def part1(data):
    asciiInput = ""

    # GOAL: if not (A or B or C) and D then jump

    # J if A is ground
    asciiInput += "NOT A J\n"
    # T if B is ground
    asciiInput += "NOT B T\n"
    # J if A or B is ground
    asciiInput += "OR T J\n"

    # T if C is ground
    asciiInput += "NOT C T\n"
    # J if (A or B or C) is ground
    asciiInput += "OR T J\n"

    # J if (A or B or C) and D is ground
    asciiInput += "AND D J\n"

    # final command
    asciiInput += "WALK\n"

    intcode_input = asciiToIntcodeInput(asciiInput)
    intcoder = Intcode(data, intcode_input)
    intcoder.run()

    # check intocder output
    if len(intcoder.output) > 0:
        if intcoder.output[-1] > 127:
            print("hull damage:", intcoder.output[-1])
        else:
            print("droid fell")
            print_2d_grid(intcodeOutputToAscii(intcoder.output))
            print()
    else:
        print("ERROR: no intcoder output??")
Esempio n. 11
0
def part2(data):
    print(data)
    intcoder = Intcode(data, [2])
    intcoder.run()
    print(intcoder.output)
Esempio n. 12
0
def part1(data):
    print(data)
    intcoder = Intcode(data, [1], debug=True)
    intcoder.run()
    print(intcoder.output)
Esempio n. 13
0
def part2(data, input):
    print(data)
    intcoder = Intcode(data, [input])
    intcoder.run()
    print(intcoder.output[0])
Esempio n. 14
0
def part1(data, input):
    print(data)
    intcoder = Intcode(data, [input], debug=True)
    intcoder.run()
    print(intcoder.output[-1])