Clean up day 6

This commit is contained in:
Sijmen 2023-12-25 12:20:24 +01:00
parent ea8d287db5
commit f98cac8651

View file

@ -2,11 +2,13 @@ import fileinput
from math import ceil, floor, sqrt from math import ceil, floor, sqrt
def race(time, dist): def race(time, dist):
x1 = (time - sqrt(time * time - 4 * dist)) / 2 discr = sqrt(time * time - 4 * dist)
x2 = (time + sqrt(time * time - 4 * dist)) / 2 x1 = (time - discr) / 2
x2 = (time + discr) / 2
x1, x2 = floor(x1) + 1, ceil(x2) - 1 x1, x2 = floor(x1) + 1, ceil(x2) - 1
return x2 - x1 + 1 return x2 - x1 + 1
def main():
input = list(fileinput.input()) input = list(fileinput.input())
times = [int(x) for x in input[0][11:].split()] times = [int(x) for x in input[0][11:].split()]
distances = [int(x) for x in input[1][11:].split()] distances = [int(x) for x in input[1][11:].split()]
@ -20,3 +22,5 @@ dist = int(input[1][11:].replace(" ", ""))
part2 = race(time, dist) part2 = race(time, dist)
print(part1, part2) print(part1, part2)
main()