Пример #1
0
def main() -> list[int]:
    tiles_to_flip = read_data('day24')
    pattern = flip_tiles(tiles_to_flip)
    result_1 = len(pattern)
    pattern_100 = update_pattern(pattern, 100)
    result_2 = len(pattern_100)
    return [result_1, result_2]
Пример #2
0
def main() -> list[int]:
    layout = read_data('day11')
    stable_layout_1 = step_until_stable(layout, 1, 4)
    n_occupied_1 = count_occupied(stable_layout_1)
    stable_layout_2 = step_until_stable(layout, 0, 5)
    n_occupied_2 = count_occupied(stable_layout_2)
    return [n_occupied_1, n_occupied_2]
Пример #3
0
def main() -> list[Union[int, str]]:
    items = read_data('day21')
    items = process_items(items)
    allergens_map = infer_allergens(items)
    result_1 = count_not_allergens(items, allergens_map)
    result_2 = list_dangerous_ingredients(allergens_map)
    return [result_1, result_2]
Пример #4
0
def main() -> list[int]:
    instructions = read_data('day12')
    position_wrong, facing = follow_instructions_wrong(instructions)
    distance_wrong = manhattan_distance(position_wrong)
    position_right, waypoint = follow_instructions_right(instructions)
    distance_right = manhattan_distance(position_right)
    return [distance_wrong, distance_right]
Пример #5
0
def main() -> list[int]:
    cups, first_cup = initialise_cups(read_data('day23'))
    cups_1 = play_cups(cups, first_cup, 100)
    result_1 = as_int(get_after(cups_1, 1, len(cups_1)-1))
    cups_2 = extend_cups(cups, first_cup, 1000000)
    cups_2 = play_cups(cups_2, first_cup, 10000000)
    result_2 = prod(get_after(cups_2, 1, 2))
    return [result_1, result_2]
Пример #6
0
def main() -> list[int]:
    equation_strs = read_data('day18')
    equations = interpret_equations(equation_strs)
    results_simple = solve_equations(equations, advanced=False)
    result_1 = sum(results_simple)
    results_advanced = solve_equations(equations, advanced=True)
    result_2 = sum(results_advanced)
    return [result_1, result_2]
Пример #7
0
def main() -> list[int]:
    tiles_raw = read_data('day20', sep='\n\n')
    tiles = process_tiles(tiles_raw)
    layout = find_layout(tiles)
    result_1 = prod([layout[i][j]['index'] for i in (0, -1) for j in (0, -1)])
    image = stitch_image(layout)
    new_image, monsters = count_monsters(image)
    result_2 = new_image.count('#')
    return [result_1, result_2]
Пример #8
0
def main(n_step: int = 6) -> list[int]:
    cubes_flat = read_data('day17')
    cubes_flat = [list(row) for row in cubes_flat]
    cubes_3d = [cubes_flat]
    cubes_3d = take_n_steps(cubes_3d, n_step)
    result_1 = count_active(cubes_3d)
    cubes_4d = [[cubes_flat]]
    cubes_4d = take_n_steps(cubes_4d, n_step)
    result_2 = count_active(cubes_4d)
    return [result_1, result_2]
Пример #9
0
def main() -> list[int]:
    instructions = parse_instructions_list(read_data('day08'))
    try:
        boot(instructions, 0, 0, [])
    except InfiniteLoopException as ile:
        accumulator_broken = ile.args[0]
    else:
        raise RuntimeError
    accumulator_fixed = find_wrong_instruction(instructions)
    return [accumulator_broken, accumulator_fixed]
Пример #10
0
def main(my_colour: str = 'shiny gold') -> list[int]:
    rules_list = read_data('day07')
    rules = dict(parse_contents(rule_str) for rule_str in rules_list)
    count_mine = sum(can_contain(colour, my_colour, rules) for colour in rules)
    inside_mine = sum_inside(my_colour, rules)
    return [count_mine, inside_mine]
Пример #11
0
def main() -> list[int]:
    tree_map = read_data('day03')
    n_tree_1 = count_trees(tree_map, SLOPE_1['right'], SLOPE_1['down'])
    result_2 = prod(
        count_trees(tree_map, s['right'], s['down']) for s in SLOPES)
    return [n_tree_1, result_2]
Пример #12
0
def main() -> list[int]:
    data = read_data('day02')
    n_valid_1 = count_valid(data, 1)
    n_valid_2 = count_valid(data, 2)
    return [n_valid_1, n_valid_2]
Пример #13
0
def main() -> list[int]:
    cards = read_data('day05')
    id_list = [seat_id(card) for card in cards]
    highest_id = max(id_list)
    my_id = find_missing_id(id_list)
    return [highest_id, my_id]