advent_of_code/2023/day6/python/main.py

29 lines
551 B
Python

import numpy as np
import math
def quadratic_formula(a,b,c):
temp= np.sqrt((b**2)-(4*a*c))
return (np.ceil((-b+temp)/(2*a)+0.00000001), np.ceil((-b-temp)/(2*a)-0.00000001))
# times = [63, 78, 94, 68]
# distances = [411, 1274, 2047, 1035]
times = [7,15,30]
distances = [9,40,200]
# times = [63789468]
# distances = [411127420471035]
# times = [71530]
# distances = [940200]
answer = 1
for i in range(len(times)):
a, b = quadratic_formula(-1, times[i], -distances[i])
answer = answer * (b-a)
print(a,b,answer)
print(answer)