Skip to content
Snippets Groups Projects
Verified Commit 44db9ef4 authored by Christopher Bohn's avatar Christopher Bohn :thinking:
Browse files

Completed 2023 Day 06

parent 0e9fa0fd
Branches
Tags
No related merge requests found
import functools
import itertools
from typing import List, Tuple
from ImportData import import_data
day: int = 6
sample_data: List[str] = '''
Time: 7 15 30
Distance: 9 40 200
'''.split('\n')[1:-1]
data_structure: type = List[Tuple[int, int]]
def parse_data1(data: List[str]) -> data_structure:
times: List[int] = [int(time) for time in data[0].split(':')[1].strip().split()]
distances: List[int] = [int(distance) for distance in data[1].split(':')[1].strip().split()]
tuples = []
for index, _ in enumerate(times):
tuples.append((times[index], distances[index]))
return tuples
def get_number_of_winning_options(race: Tuple[int, int]) -> int:
time: int = race[0]
record_distance: int = race[1]
number_of_wins: int = 0
for hold_time in range(1, time):
move_time = time - hold_time
speed = hold_time
distance = speed * move_time
if distance > record_distance:
number_of_wins += 1
return number_of_wins
def part1(data: data_structure) -> int:
return functools.reduce(lambda x, y: x * y, [get_number_of_winning_options(race) for race in data])
def parse_data2(data: List[str]) -> data_structure:
times: List[str] = [time for time in data[0].split(':')[1].strip().split()]
distances: List[str] = [distance for distance in data[1].split(':')[1].strip().split()]
return [((int(''.join(times))), (int(''.join(distances))))]
def part2(data: data_structure) -> int:
return get_number_of_winning_options(data[0])
if __name__ == '__main__':
production_ready = True
raw_data = import_data(day) if production_ready else sample_data
print(part1(parse_data1(raw_data)))
print(part2(parse_data2(raw_data)))
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment