Ejemplo n.º 1
0
def find_values_p1(input_file):
    values = get_input(input_file)
    for a, b in itertools.combinations(values, 2):
        if a + b == 2020:
            product = a * b
            return f'{a=} {b=} {product=}'
    return f'not found'
Ejemplo n.º 2
0
def find_values_p2(input_file):
    values = get_input(input_file)
    for a, b, c in itertools.combinations(values, 3):
        if a + b + c == 2020:
            product = a * b * c
            return f'{a=} {b=} {c=} {product=}'
    return f'not found'
Ejemplo n.º 3
0
def find_values_p1_brute_force(input_file):
    values = get_input(input_file)
    for value1 in values:
        for value2 in values:
            if value1 != value2:
                total = value1 + value2
                if total == 2020:
                    product = value1 * value2
                    return f'{value1=} {value2=} {product=}'
    return 'none found'
Ejemplo n.º 4
0
def find_values_p2_brute_force(input_file):
    values = get_input(input_file)
    for value1 in values:
        for value2 in values:
            for value3 in values:
                if (value1 != value2 and value1 != value3
                        and value2 != value3):
                    total = value1 + value2 + value3
                    if total == 2020:
                        product = value1 * value2 * value3
                        return f'{value1=} {value2=} {value3=} {product=}'

    return 'none found'
Ejemplo n.º 5
0
def _parse_input(input_file):
    lines = get_input(input_file)
    parsed_lines = []
    for line in lines:
        parsed_lines.append(int(line))
    return parsed_lines