Day 6 - Advent of Code 2023

Working solutions for the day 6 puzzles.

Part One

""" day_06_01.py """

# usage: python3 day_06_01.py < input

import math


def travel(hold, limit):
    """ travel distance """
    return max(0, (limit - hold)) * hold


times = map(int, input().split(':')[-1].split())
distances = map(int, input().split(':')[-1].split())

answer = []
for duration, record in zip(times, distances):
    count = sum(1 for i in range(duration) if travel(i, duration) > record)
    answer.append(count)

print(math.prod(answer))

Part Two

""" day_06_02.py """

# usage: python3 day_06_02.py < input


def travel(hold, limit):
    """ travel distance """
    return max(0, (limit - hold)) * hold


time = int(''.join(input().split(':')[-1].split()))
distance = int(''.join(input().split(':')[-1].split()))

count = sum(1 for i in range(time) if travel(i, time) > distance)

print(count)