def solution2(file_name): slopes = [(1, 1), (3, 1), (5, 1), (7, 1), (1, 2)] map_lines = prepare_data(file_name) trees_on_slope = [ count_trees_on_slope(map_lines, slope) for slope in slopes ] return math_utils.prod(trees_on_slope)
def calculate_with_chinese_remainder(ids_with_gaps): bus_ids = ids_with_gaps.keys() produit_total = math_utils.prod(bus_ids) e_a_s = [ calculate_prod_e_a(calculate_e(bus_id, produit_total), ids_with_gaps, bus_id) for bus_id in bus_ids ] return sum(e_a_s) % produit_total
def solution2(input): parsed = prepare_data(input) valid_tickets = parsed.remove_errors() num_values = len(parsed.fields) values_per_index = group_ticket_values_by_index(num_values, valid_tickets) valid_index_by_field = get_valid_index_by_field(parsed, values_per_index) return math_utils.prod([ parsed.your_ticket.values[i] for i in dict( filter(lambda field: field[1].startswith('departure'), valid_index_by_field.items())).keys() ])
def solution2(file_name): prepared_data = prepare_data(file_name) gaps = find_gaps(prepared_data) consecutive = 0 multiples = [] for gap in gaps: if gap == 1: consecutive += 1 else: if consecutive == 2: multiples.append(2) elif consecutive == 3: multiples.append(4) elif consecutive == 4: multiples.append(7) consecutive = 0 return math_utils.prod(multiples)
def test_solution(): result = solution('input') assert 51214443014783 == math_utils.prod(result)
def solution(file_name): tiles = prepare_data(file_name) corner_tiles = list(filter(lambda tile: len(tile.neighbours) == 2, tiles)) result = [tile.id for tile in corner_tiles] print(math_utils.prod(result)) return result
def multiply(numbers): return math_utils.prod(numbers)