This commit is contained in:
2024-12-19 17:38:34 +01:00
parent c6d795800e
commit f9ab75b54f

View File

@@ -5,12 +5,12 @@ from time import time
import numpy as np
start_time = time()
#file = "./input.txt"
#XY_MIN = 200000000000000
#XY_MAX = 400000000000000
file = "./ex.txt"
XY_MIN = 7
XY_MAX = 27
file = "./input.txt"
XY_MIN = 200000000000000
XY_MAX = 400000000000000
#file = "./ex.txt"
#XY_MIN = 7
#XY_MAX = 27
def berechne_schnittpunkt(p1, v1, p2, v2):
@@ -50,9 +50,8 @@ def read_input(filename:str)->list[list[int]]:
if line == "":
continue
else:
pat = r'^(-?\d+), (-?\d+), -?\d+ \@ (-?\d+), (-?\d+), -?\d+$'
pat = r'^(-?\d+), +(-?\d+), +-?\d+ +\@ +(-?\d+), +(-?\d+), +-?\d+$'
match = re.match(pat, line)
if match:
result.append(list(map(int,[match.group(1), match.group(2), match.group(3), match.group(4)])))
input_file.close()
return result
@@ -66,18 +65,17 @@ if __name__ == "__main__":
v_2 = (-1, -2)
schnitt_punkt = berechne_schnittpunkt(p_1, v_1, p_2, v_2)
if schnitt_punkt:
print(f"Der Schnittpunkt liegt bei: {schnitt_punkt[0]} {type(schnitt_punkt[0])} {schnitt_punkt[1]}")
print(f"Der Schnittpunkt liegt bei: {schnitt_punkt[0]} {schnitt_punkt[1]}")
else:
print("Die Strahlen schneiden sich nicht.")
'''
d = read_input(file)
for i in range(len(d)):
for j in range(i, len(d)):
s = berechne_schnittpunkt((d[i][0],d[j][0]), (d[i][2],d[j][2]), (d[i][1],d[j][1]), (d[i][3],d[j][3]))
if s:
print(s[0],s[1])
for j in range(i+1, len(d)):
s = berechne_schnittpunkt((d[i][0],d[i][1]), (d[i][2],d[i][3]),
(d[j][0],d[j][1]), (d[j][2],d[j][3]))
if s and XY_MIN < s[0] < XY_MAX and XY_MIN < s[1] < XY_MAX:
print("------------", s[0], s[1])
sol += 1
print(f"Solution Part1: {sol}")
print(f'Runtime: {time()-start_time:.2f} s')