Minor cleaning 2023.
This commit is contained in:
@@ -1,11 +1,8 @@
|
||||
import sys
|
||||
from collections import defaultdict
|
||||
from dataclasses import dataclass
|
||||
|
||||
import numpy as np
|
||||
|
||||
from sympy import solve, symbols
|
||||
|
||||
|
||||
lines = sys.stdin.read().splitlines()
|
||||
|
||||
positions = [
|
||||
@@ -19,7 +16,7 @@ velocities = [
|
||||
low, high = [7, 27] if len(positions) <= 10 else [200000000000000, 400000000000000]
|
||||
count = 0
|
||||
for i, (p1, v1) in enumerate(zip(positions, velocities)):
|
||||
for p2, v2 in zip(positions[i + 1:], velocities[i + 1:]):
|
||||
for p2, v2 in zip(positions[i + 1 :], velocities[i + 1 :]):
|
||||
p, r = p1[:2], v1[:2]
|
||||
q, s = p2[:2], v2[:2]
|
||||
|
||||
@@ -31,7 +28,7 @@ for i, (p1, v1) in enumerate(zip(positions, velocities)):
|
||||
continue
|
||||
else:
|
||||
assert rs != 0
|
||||
t = np.cross((q - p), s) / rs
|
||||
t = np.cross((q - p), s) / rs
|
||||
u = np.cross((q - p), r) / rs
|
||||
|
||||
if t >= 0 and u >= 0:
|
||||
@@ -50,14 +47,16 @@ print(f"answer 1 is {answer_1}")
|
||||
# p3 + t3 * v3 == p0 + t3 * v0
|
||||
# ...
|
||||
# pn + tn * vn == p0 + tn * v0
|
||||
#
|
||||
#
|
||||
|
||||
# we can solve with only 3 lines since each lines contains 3
|
||||
# we can solve with only 3 lines since each lines contains 3
|
||||
# equations (x / y / z), so 3 lines give 9 equations and 9
|
||||
# variables: position (3), velocities (3) and times (3).
|
||||
n = 3
|
||||
|
||||
x, y, z, vx, vy, vz, *ts = symbols('x y z vx vy vz ' + ' '.join(f't{i}' for i in range(n + 1)))
|
||||
x, y, z, vx, vy, vz, *ts = symbols(
|
||||
"x y z vx vy vz " + " ".join(f"t{i}" for i in range(n + 1))
|
||||
)
|
||||
equations = []
|
||||
for i, ti in zip(range(n), ts):
|
||||
for p, d, pi, di in zip((x, y, z), (vx, vy, vz), positions[i], velocities[i]):
|
||||
|
Reference in New Issue
Block a user