diff --git a/2023/6.py b/2023/6.py new file mode 100644 index 0000000..dcadeeb --- /dev/null +++ b/2023/6.py @@ -0,0 +1,24 @@ +from math import pow, ceil, floor + +lines = [l.split() for l in open("input.txt", 'r').read().splitlines()] +races = [(int(lines[0][i]), int(lines[1][i])) for i in range(1,len(lines[0]))] +#[(time, record)] + +#d = t * v +#charge + t = time +#t = time - charge +#v = charge +#d = (time - charge) * charge +#d = -charge^2 + time*charge + +summa = 1 + +for race in races: + a = -1 + b = race[0] + c = -race[1] + rangeStart = floor((-b + pow((pow(b,2)-(4*a*c)),0.5)) / (2*a)) + 1 + rangeEnd = ceil((-b - pow((pow(b,2)-(4*a*c)),0.5)) / (2*a)) - 1 + summa *= (rangeEnd-rangeStart+1) + +print(summa) \ No newline at end of file