Esempio n. 1
0
def solve_part_one():
    program = [int(d) for d in read_file_lines("day_07.txt")[0].split(',')]
    phase_sequence = [0, 1, 2, 3, 4]
    max_thruster_signal = 0
    for perm_sequence in itertools.permutations(phase_sequence):
        signal = thruster_signal(program.copy(), list(perm_sequence))
        if signal > max_thruster_signal:
            max_thruster_signal = signal
    return max_thruster_signal
Esempio n. 2
0
def solve_part_2():
    program = [int(n) for n in read_file_lines("day_02.txt")[0].split(',')]

    for noun in range(0, 100):
        for verb in range(0, 100):
            program[1] = noun
            program[2] = verb
            if process_program(program.copy())[0] == 19690720:
                return 100 * noun + verb
Esempio n. 3
0
def solve_part_one():
    data = [int(d) for d in read_file_lines("day_08.txt")[0]]
    image = WireImage(data, 25, 6)
    best_ones = 0
    best_twos = 0
    min_zeroes = 25 * 6
    for layer_n in range(image.num_layers):
        layer = image.get_layer(layer_n)
        zeroes = 0
        ones = 0
        twos = 0
        for d in layer:
            if d == 0:
                zeroes += 1
            elif d == 1:
                ones += 1
            elif d == 2:
                twos += 1
        if zeroes < min_zeroes:
            min_zeroes = zeroes
            best_ones = ones
            best_twos = twos
    return best_ones * best_twos
Esempio n. 4
0
def solve_part_two():
    orbit_map = build_map(read_file_lines("day_06.txt"))
    path_you = build_path(orbit_map, "YOU")
    path_san = build_path(orbit_map, "SAN")
    return find_transfers(path_you, path_san)
Esempio n. 5
0
def solve_part_one():
    return count_orbits(build_map(read_file_lines("day_06.txt")))
Esempio n. 6
0
def solve_part_one():
    program = [int(n) for n in read_file_lines("day_05.txt")[0].split(',')]
    return process_program(program, [1])
def solve_part_2():
    lines = read_file_lines("day_03.txt")
    return lowest_steps_to_intersection(lines[0], lines[1])
def solve_part_1():
    lines = read_file_lines("day_03.txt")
    return dist_to_closest_intersection(lines[0], lines[1])
Esempio n. 9
0
def solve_part_1():
    program = [int(n) for n in read_file_lines("day_02.txt")[0].split(',')]
    program[1] = 12
    program[2] = 2
    return process_program(program)
Esempio n. 10
0
def solve_part_two():
    program = [int(d) for d in read_file_lines("day_09.txt")[0].split(',')]
    return get_output(program, 2)
Esempio n. 11
0
def solve_part_two():
    data = [int(d) for d in read_file_lines("day_08.txt")[0]]
    image = WireImage(data, 25, 6)
    image.print_image()
    return image.decode_image()