day 6 hype
This commit is contained in:
parent
64f1b65c9b
commit
ea8d287db5
1 changed files with 22 additions and 0 deletions
22
day06.py
Normal file
22
day06.py
Normal file
|
@ -0,0 +1,22 @@
|
|||
import fileinput
|
||||
from math import ceil, floor, sqrt
|
||||
|
||||
def race(time, dist):
|
||||
x1 = (time - sqrt(time * time - 4 * dist)) / 2
|
||||
x2 = (time + sqrt(time * time - 4 * dist)) / 2
|
||||
x1, x2 = floor(x1) + 1, ceil(x2) - 1
|
||||
return x2 - x1 + 1
|
||||
|
||||
input = list(fileinput.input())
|
||||
times = [int(x) for x in input[0][11:].split()]
|
||||
distances = [int(x) for x in input[1][11:].split()]
|
||||
|
||||
part1 = 1
|
||||
for time, dist in zip(times, distances):
|
||||
part1 *= race(time, dist)
|
||||
|
||||
time = int(input[0][11:].replace(" ", ""))
|
||||
dist = int(input[1][11:].replace(" ", ""))
|
||||
part2 = race(time, dist)
|
||||
|
||||
print(part1, part2)
|
Loading…
Reference in a new issue