Advent of Code Solutions

I have set myself a personal challenge to try and get up to date with advent of code, a set of programming challenges released each December.

Each day has 2 related problems, for a total of 50 problems per year. Each button below will show my code solving that problem. Green buttons where I have solved both problems of the day, orange where I have only solved the first one and red where I haven't solved either.

2015 2016 2017 2018 2019 2020 2021 2022 2023 2024
Not started
Part 1 completed
Both parts completed
from util.input import get_input

def part_1():
    
    puzzle_input = get_input(2015, 17)

    jars = sorted(map(int,puzzle_input.splitlines()), reverse=True)

    def get_valid_combinations(remaining_jars, sequence):

        target = 150 - sum(sequence)

        valid_combinations = []
        for i, jar in enumerate(remaining_jars):
            if target - jar == 0:
                valid_combinations.append(sequence + [jar])
            elif target - jar < 0:
                continue
            else:
                valid_combinations += get_valid_combinations(remaining_jars[i+1:], sequence + [jar])

        return valid_combinations

    return len(get_valid_combinations(jars, []))

def part_2():
    
    puzzle_input = get_input(2015, 17)

    jars = sorted(map(int,puzzle_input.splitlines()), reverse=True)

    def get_valid_combinations(remaining_jars, sequence):

        target = 150 - sum(sequence)

        valid_combinations = []
        for i, jar in enumerate(remaining_jars):
            if target - jar == 0:
                valid_combinations.append(sequence + [jar])
            elif target - jar < 0:
                continue
            else:
                valid_combinations += get_valid_combinations(remaining_jars[i+1:], sequence + [jar])

        return valid_combinations

    all_combinations = get_valid_combinations(jars, [])
    min_length = len(min(all_combinations, key=len))

    return sum(len(c) == min_length for c in all_combinations)