diff options
author | Tomasz Kramkowski <tomasz@kramkow.ski> | 2023-12-07 13:56:49 +0000 |
---|---|---|
committer | Tomasz Kramkowski <tomasz@kramkow.ski> | 2023-12-07 13:56:49 +0000 |
commit | eb5190b7d348df23dfa848a5cdbfead3cbfc38ce (patch) | |
tree | 766f238a11323193178621a167ebea5499f725e9 | |
parent | 150b940133b9df43d320bf9e4a1596b0964d267a (diff) | |
download | aoc2023-eb5190b7d348df23dfa848a5cdbfead3cbfc38ce.tar.gz aoc2023-eb5190b7d348df23dfa848a5cdbfead3cbfc38ce.tar.xz aoc2023-eb5190b7d348df23dfa848a5cdbfead3cbfc38ce.zip |
day 6
-rw-r--r-- | 6.py | 23 |
1 files changed, 23 insertions, 0 deletions
@@ -0,0 +1,23 @@ +from functools import reduce +from math import floor, sqrt +from operator import mul +from sys import stdin + + +def solve(time: int, distance: int): + root = (time - sqrt(time**2 - 4 * distance)) / 2 + first = floor(root + 1) + return time - 2 * first + 1 + + +inp = list( + zip( + *( + [int(s) for s in l.split(maxsplit=1)[1].split()] + for l in stdin.read().rstrip("\n").split("\n") + ) + ) +) + +print(reduce(mul, (solve(*i) for i in inp))) +print(solve(int("".join(str(i[0]) for i in inp)), int("".join(str(i[1]) for i in inp)))) |