-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
56 additions
and
106 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import os | ||
from task import task1, task2 | ||
import sys | ||
|
||
def parse_input(input_file_path: str) -> list[str]: | ||
file = open(input_file_path) | ||
raw_lines = file.readlines() | ||
file.close() | ||
lines = [] | ||
for line in raw_lines: | ||
lines.append(line.rstrip("\n")) | ||
return lines | ||
|
||
if __name__ == "__main__": | ||
if len(sys.argv) <= 2 or sys.argv[2] == "main": | ||
input_file = os.path.dirname(__file__) + "/solve.in" | ||
elif sys.argv[2] == "test": | ||
input_file = os.path.dirname(__file__) + "/test.in" | ||
if not os.path.exists(input_file): | ||
print("Test file doesn't exist!") | ||
exit(1) | ||
lines = parse_input(input_file) | ||
|
||
if len(sys.argv) <= 1 or sys.argv[1] == "1": | ||
task1(lines) | ||
if len(sys.argv) <= 1 or sys.argv[1] == "2": | ||
task2(lines) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import re | ||
from sympy import Symbol | ||
from sympy import solve_poly_system | ||
|
||
|
||
def task1(input_lines: list[str]): | ||
print("Unimplemented") | ||
|
||
def task2(input_lines: list[str]): | ||
lines = list(map(lambda i: list(map(int, i)), list(map(lambda i: re.match("(-?[0-9]+), (-?[0-9]+), (-?[0-9]+) @ (-?[0-9]+), (-?[0-9]+), (-?[0-9]+)", i).groups(), input_lines[:3])))) | ||
px = Symbol('px') | ||
py = Symbol('py') | ||
pz = Symbol('pz') | ||
vx = Symbol('vx') | ||
vy = Symbol('vy') | ||
vz = Symbol('vz') | ||
ts = [Symbol('t'+str(i)) for i in range(3)] | ||
equations = [] | ||
|
||
for i, l in enumerate(lines): | ||
equations.append(px + vx * ts[i] - l[0] - l[3] * ts[i]) | ||
equations.append(py + vy * ts[i] - l[1] - l[4] * ts[i]) | ||
equations.append(pz + vz * ts[i] - l[2] - l[5] * ts[i]) | ||
|
||
result = solve_poly_system(equations, px, py, pz, vx, vy, vz, *ts) | ||
print(result[0][0] + result[0][1] + result[0][2]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters