def get_result(rules: Set[Rule], my_ticket: Tuple[int], nearby_tickets: List[Tuple[int]]): departure_rules = [ rule for rule in rules if rule.name.startswith('departure') ] field_mappping = calc_field_mapping(rules, my_ticket, nearby_tickets) return multiply(my_ticket[field_mappping[departure_rule]] for departure_rule in departure_rules)
def cheat_solution(my_input): check_co_primes(my_input) interval = multiply(bus.interval for bus in my_input) result = 0 for bus in my_input: p = interval // bus.interval result += -bus.offset * pow(p, -1, bus.interval) * p return result % interval
def get_result_1st(self): return multiply(self.get_corner_tile_numbers())
def correct_tiles(tiles: List[Tile]): tiles_dict = {tile.tile_number: tile for tile in tiles} result = np.ndarray([len(tiles_dict), len(tiles_dict)], Tile) all_tiles = { possible_tiles for tile in tiles for possible_tiles in tile.get_all_possible_tiles(only_flipped=True) } corner_tiles = [] for tile_to_check in tiles: for possible_tile_to_check in tile_to_check.get_all_possible_tiles(): if get_matching_sides(possible_tile_to_check, all_tiles) == 2: corner_tiles.append(possible_tile_to_check) break return corner_tiles # print(multiply(get_corner_tiles(correct_tiles(parse_input(PUZZLE_INPUT))))) assert multiply(tile.tile_number for tile in correct_tiles(parse_input(TEST_INPUT))) == (1951 * 3079 * 2971 * 1171), \ multiply(tile.tile_number for tile in correct_tiles(parse_input(TEST_INPUT))) print( multiply(tile.tile_number for tile in correct_tiles(parse_input(PUZZLE_INPUT))))
def get_jolt_combination_amount_fast(my_input): return multiply([ get_jolt_combination_amount_slow(adapter_list[1:], adapter_list[0]) for adapter_list in split_in_3_jump_groups(my_input) ])