- Published on
Advent of Code 2023: Day 6 Solution
- Authors
- Name
- Tinker Assist
Advent of Code 2023 - Day 6 - Wait For It
Table of Contents
Part 1 Solution
We'll need to begin by reading the puzzle input
Read the Puzzle Input File
We will save our puzzle input in "day4_input.txt" and then read from that file.
file = open("day6_input.txt", "r")
input = file.read()
We will then break up the input by line:
input_list = input.split('\n')
Create Solution structure
points = 0
for card in input_list:
# We will add to our points here
print(points)
The Code
# Read each of the two input lines
times = input_list[0]
distances = input_list[1]
# Parse the input lines into more usable data
times = [int(i) for i in times.split(':')[1].split(' ') if i.isdigit()]
distances = [int(i) for i in distances.split(':')[1].split(' ') if i.isdigit()]
# loop through each time and distance index in our input
answer = 1
for ind, time in enumerate(times):
# loop through each possible "charging time" for the race and determine
# whether the resulting distance is greater than the record distance
wins = 0
for i in range(0, time):
if i*(time-i) > distances[ind]:
wins +=1
answer = answer * wins
print(answer)
Part 2 Solution
The Code
# Read each of the two input lines
times = input_list[0]
distances = input_list[1]
# parse the input to be one long race
time = int(times.split(':')[1].replace(' ', ''))
distance = int(distances.split(':')[1].replace(' ', ''))
# loop through all possible charging times in the race and count up wins
wins = 0
for i in range(0, time):
if i*(time-i) > distance:
wins +=1
print(wins)
Full code
Get the full code here.