aoc 2023 06

This commit is contained in:
Julian Brammer 2023-12-06 23:26:34 +01:00
parent caafa3ce75
commit 08711a7cf5
3 changed files with 54 additions and 0 deletions

2
2023/06/input.txt Normal file
View File

@ -0,0 +1,2 @@
Time: 41 77 70 96
Distance: 249 1362 1127 1011

50
2023/06/main.py Normal file
View File

@ -0,0 +1,50 @@
def solve_race(time, goal):
res = 0
for i in range(time+1):
speed = i
distance = speed*(time-i)
# print(f"speed: {speed}, distance: {distance}, goal: {goal}")
if distance > goal:
res += 1
# print("")
return res
def solve(file):
part1 = 1
part2 = 1
race_results = []
times = []
distances = []
#! Part 1
arr1 = file[0].split(":")[1].split(" ")
arr2 = file[1].split(":")[1].split(" ")
for i in range(len(arr1)):
if arr1[i] != "":
times.append(int(arr1[i]))
for i in range(len(arr2)):
if arr2[i] != "":
distances.append(int(arr2[i]))
for i in range(len(times)):
race_results.append(solve_race(times[i], distances[i]))
for i in range(len(race_results)):
if race_results[i] >= 0:
part1 *= race_results[i]
#! Part 2
arr1 = file[0].split(":")[1].replace(" ", "")
arr2 = file[1].split(":")[1].replace(" ", "")
part2 = solve_race(int(arr1), int(arr2))
return part1, part2
file = open("input.txt", "r").readlines()
print(solve(file))

2
2023/06/test_input.txt Normal file
View File

@ -0,0 +1,2 @@
Time: 7 15 30
Distance: 9 40 200