aoc 2023 06
This commit is contained in:
parent
caafa3ce75
commit
08711a7cf5
2
2023/06/input.txt
Normal file
2
2023/06/input.txt
Normal file
@ -0,0 +1,2 @@
|
||||
Time: 41 77 70 96
|
||||
Distance: 249 1362 1127 1011
|
50
2023/06/main.py
Normal file
50
2023/06/main.py
Normal 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
2
2023/06/test_input.txt
Normal file
@ -0,0 +1,2 @@
|
||||
Time: 7 15 30
|
||||
Distance: 9 40 200
|
Loading…
Reference in New Issue
Block a user