Ejemplo n.º 1
0
def part_two_with_finished_machine():
    for noun in range(99):
        for verb in range(99):
            machine = IntcodeOpMachine(create_data_list(noun, verb))
            machine.run_until_halt()
            if machine.instructions[0] == 19690720:
                return noun * 100 + verb
Ejemplo n.º 2
0
def part_two():
    continuous_feed = 'n'
    inputs = []
    inputs.extend(mov_func_main())
    inputs.extend(mov_func_a())
    inputs.extend(mov_func_b())
    inputs.extend(mov_func_c())
    inputs.extend([ord(continuous_feed), ord('\n')])

    instructions = list(data)
    instructions[0] = 2
    machine = IntcodeOpMachine(instructions, input_vals=inputs)
    machine.run_until_halt()
    return machine.output[-1]
Ejemplo n.º 3
0
def part_one():
    w = 50
    h = 50
    disp = [['.'] * w for i in range(h)]
    total_count = 0
    for y in range(h):
        for x in range(w):
            machine = IntcodeOpMachine(list(data), input_vals=[x, y])
            machine.run_until_halt()
            if machine.output[-1] == 1:
                disp[y][x] = '#'
                total_count += 1

    for row in disp:
        print(''.join(row))
    return total_count
Ejemplo n.º 4
0
def part_two():
	phases = [''.join(p) for p in permutations('56789')]
	max_input = 0
	for series in phases:
		next_input = 0
		machines = []
		for phase in series:
			machines.append(IntcodeOpMachine(list(data), input_vals=[int(phase), next_input]))

		active_machines = []
		for machine in cycle(machines):
			if machine not in active_machines and not machine.halted:
				active_machines.append(machine)
			machine.input_vals[1] = next_input
			exit_code = machine.run()
			next_input = machine.output[-1]

			if exit_code == 99:
				active_machines.remove(machine)
			if not active_machines:
				break

		if next_input > max_input:
			max_input = next_input
	return max_input
Ejemplo n.º 5
0
def part_two():
    grid = [['.' for i in range(100)] for i in range(100)]
    grid[0][0] = 'W'
    counter, grid = run_robot(IntcodeOpMachine(list(data)), grid)

    out_str = ''
    for row in grid:
        row_str = ''.join(row).replace('B', '.').replace('.', ' ')
        out_str += row_str + '\n' if row_str.strip() != '' else ''
    return out_str
Ejemplo n.º 6
0
def part_one():
    machine = IntcodeOpMachine(list(data), input_vals=[1])
    machine.run_until_halt()
    lines = ''.join((chr(i) for i in machine.output)).strip().split('\n')

    intersection_points = set()
    for i, line in enumerate(lines):
        if 0 < i < len(lines) - 2:
            for j, char in enumerate(line):
                if 0 < j < len(line) - 1:
                    if char == '#':
                        if lines[i][j + 1] == '#' and lines[i][
                                j - 1] == '#' and lines[
                                    i + 1][j] == '#' and lines[i -
                                                               1][j] == '#':
                            intersection_points.add((
                                i,
                                j,
                            ))

    return sum(x * y for x, y in intersection_points)
Ejemplo n.º 7
0
def part_one():
    ship_map = [[' ' for i in range(50)] for i in range(50)]
    curr_pos = (
        len(ship_map) // 2,
        len(ship_map[0]) // 2,
    )
    ship_map[curr_pos[1]][curr_pos[0]] = 'D'
    # wall_positions = set()
    # visited_positions = set()
    draw_map(ship_map)

    machine = IntcodeOpMachine(list(data), input_vals=[1])
    exit_code = 0
    # hit_wall_count = 0
    while exit_code != 99:
        exit_code = machine.run(dynamic_input=True)
        if exit_code == 3:
            machine.add_input(determine_next_direction(ship_map, curr_pos))
        elif exit_code == 4:
            next_pos = get_next_position(curr_pos, machine.input_vals[-1])
            resp = machine.output[-1]
            if resp == 0:
                # wall_positions.add(next_pos)
                # if ship_map[next_pos[1]][next_pos[0]] == ' ':
                ship_map[next_pos[1]][next_pos[0]] = '#'
                # hit_wall_count += 1
            elif resp == 1:
                ship_map[next_pos[1]][next_pos[0]] = 'D'
                ship_map[curr_pos[1]][curr_pos[0]] = '.'
                curr_pos = next_pos + tuple()
                # visited_positions.add(curr_pos)
                # hit_wall_count = 0
            elif resp == 2:
                print("MADE IT {}".format(next_pos))
                # break
        draw_map(ship_map)
    draw_map(ship_map)
    return
Ejemplo n.º 8
0
def part_two():
    grid = [[' ' for i in range(45)] for i in range(24)]
    i = 0
    score = 0
    list_data = list(data)
    list_data[0] = 2
    machine = IntcodeOpMachine(list_data)
    ball_pos = 0
    paddle_pos = 0
    while True:
        exit_code = machine.run(dynamic_input=True)
        if exit_code == 3:
            machine.add_input(compare_vals(ball_pos, paddle_pos))
        elif exit_code == 4:
            i = (i + 1) % 3
            if i == 0:
                if machine.output[-3] == -1 and machine.output[-2] == 0:
                    score = machine.output[-1]
                else:
                    tile_type = machine.output[-1]
                    tile_disp = ' '
                    if tile_type == 1:
                        tile_disp = 'X'
                    elif tile_type == 2:
                        tile_disp = '-'
                    elif tile_type == 3:
                        tile_disp = '_'
                        paddle_pos = machine.output[-3]
                    elif tile_type == 4:
                        tile_disp = 'o'
                        ball_pos = machine.output[-3]
                    grid[machine.output[-2]][machine.output[-3]] = tile_disp
                machine.output.clear()
        elif exit_code == 99:
            break
    return score
Ejemplo n.º 9
0
def part_one():
	phases = [''.join(p) for p in permutations('01234')]
	max_input = 0
	for series in phases:
		next_input = 0
		machines = []
		for phase in series:
			machines.append(IntcodeOpMachine(list(data), input_vals=[int(phase), next_input]))

		for machine in machines:
			machine.input_vals[1] = next_input
			machine.run_until_halt()
			next_input = machine.output[-1]

		if next_input > max_input:
			max_input = next_input
	return max_input
Ejemplo n.º 10
0
def part_one_with_finished_machine():
    machine = IntcodeOpMachine(list(data), input_vals=[1])
    machine.run_until_halt()
    return machine.output
Ejemplo n.º 11
0
def part_one():
    machine = IntcodeOpMachine(list(data))
    machine.run_until_halt()
    return machine.output[2::3].count(2)
Ejemplo n.º 12
0
def part_one_with_finished_machine():
    machine = IntcodeOpMachine(create_data_list(12, 2))
    machine.run_until_halt()
    return machine.instructions[0]
Ejemplo n.º 13
0
def part_one():
    grid = [['.' for i in range(100)] for i in range(100)]
    counter, grid = run_robot(IntcodeOpMachine(list(data)), grid)
    return counter