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


hex_chars = 'abcdef0123456789'

def part_1():
    puzzle_input = get_input(2015, 8)
    total = 0
    for line in puzzle_input.splitlines():
        code_length = len(line)
        line = line[1:-1]
        line = line.replace(r'\\', '?')
        line = line.replace(r'\"', '?')

        for h1 in hex_chars:
            for h2 in hex_chars:
                line = line.replace(r'\x' + h1 + h2 , '?')
        memory_length = len(line)
        total += code_length - memory_length
        
    return total

def part_2():
    puzzle_input = get_input(2015, 8)
    total = 0
    for line in puzzle_input.splitlines():
        code_length = len(line)
        line = line.replace(r'"', '??')
        line = line.replace('\\', '??')
        line = f'"{line}"'
        
        total += len(line) - code_length
        
    return total