summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorlonkaars <loek@pipeframe.xyz>2023-12-06 22:23:26 +0100
committerlonkaars <loek@pipeframe.xyz>2023-12-06 22:23:26 +0100
commit08a11d4a608714e9fe56f899bc9f07003ee237be (patch)
treee520bd7fbc85d93dbd0e99c29389197a3beebf8c
parent792b94cfebae617b36361aa2779dc73b10e45069 (diff)
day 6 part 2
-rwxr-xr-x06/main.py23
1 files changed, 7 insertions, 16 deletions
diff --git a/06/main.py b/06/main.py
index 9951621..8418a4a 100755
--- a/06/main.py
+++ b/06/main.py
@@ -1,22 +1,13 @@
#!/bin/python3
import sys
+from math import sqrt
-times = [int(x) for x in input().split(":")[1].split()]
-distances = [int(x) for x in input().split(":")[1].split()]
-races = [(times[i], distances[i],) for i in range(len(times))]
+max_time = int(input().split(":")[1].replace(' ', ''))
+record_dist = int(input().split(":")[1].replace(' ', ''))
-def distance_for_race_len(race_len, hold_time):
- if hold_time <= 0: return 0
- if hold_time >= race_len: return 0
- return round((race_len - hold_time) * hold_time)
+lower_bound = ( max_time - sqrt( max_time ** 2 - 4 * record_dist ) ) / 2
+upper_bound = ( max_time + sqrt( max_time ** 2 - 4 * record_dist ) ) / 2
+possible_distances = round(abs(lower_bound - upper_bound))
-output = 1
-for max_time, record_dist in races:
- possible_distances = [distance_for_race_len(max_time, x) for x in range(max_time)]
- possible_distances = list(enumerate(possible_distances))
- possible_distances = [p for p in possible_distances if p[1] > record_dist]
-
- output *= len(possible_distances)
-
-print(f">> {output}")
+print(f">> {possible_distances}")