StyleInCode

RSS

 

Day 9 - Advent of Code 2025

9 December 2025

Working solutions for the day 9 puzzles.

Part One

""" day_09_01.py """

# usage: python3 day_09_01.py

from itertools import combinations


def get(filename):
    """ contents of filename """
    with open(filename, 'r', encoding='utf-8') as infile:
        data = infile.read()

    return data


def test(data, given_solution):
    """ testing """
    assert solve(data) == given_solution


def area(p1, p2):
    """ area of rectangle with opposite corners """
    (x1, y1), (x2, y2) = p1, p2
    return (abs(x1 - x2) + 1) * (abs(y1 - y2) + 1)


def solve(data):
    """ solve the puzzle """
    tiles = [tuple(map(int, row.split(','))) for row in data.splitlines()]

    return max(area(t1, t2) for t1, t2 in combinations(tiles, 2))


if __name__ == '__main__':
    test(get('example01'), 50)

    puzzle = get('input')
    solution = solve(puzzle)

    print(solution)

Part Two


Categories

Links