summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTomasz Kramkowski <tomasz@kramkow.ski>2023-12-07 13:56:49 +0000
committerTomasz Kramkowski <tomasz@kramkow.ski>2023-12-07 13:56:49 +0000
commiteb5190b7d348df23dfa848a5cdbfead3cbfc38ce (patch)
tree766f238a11323193178621a167ebea5499f725e9
parent150b940133b9df43d320bf9e4a1596b0964d267a (diff)
downloadaoc2023-eb5190b7d348df23dfa848a5cdbfead3cbfc38ce.tar.gz
aoc2023-eb5190b7d348df23dfa848a5cdbfead3cbfc38ce.tar.xz
aoc2023-eb5190b7d348df23dfa848a5cdbfead3cbfc38ce.zip
day 6
-rw-r--r--6.py23
1 files changed, 23 insertions, 0 deletions
diff --git a/6.py b/6.py
new file mode 100644
index 0000000..948f152
--- /dev/null
+++ b/6.py
@@ -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))))