24-part1
This commit is contained in:
30
24/24-1.py
30
24/24-1.py
@@ -5,12 +5,12 @@ from time import time
|
|||||||
import numpy as np
|
import numpy as np
|
||||||
|
|
||||||
start_time = time()
|
start_time = time()
|
||||||
#file = "./input.txt"
|
file = "./input.txt"
|
||||||
#XY_MIN = 200000000000000
|
XY_MIN = 200000000000000
|
||||||
#XY_MAX = 400000000000000
|
XY_MAX = 400000000000000
|
||||||
file = "./ex.txt"
|
#file = "./ex.txt"
|
||||||
XY_MIN = 7
|
#XY_MIN = 7
|
||||||
XY_MAX = 27
|
#XY_MAX = 27
|
||||||
|
|
||||||
|
|
||||||
def berechne_schnittpunkt(p1, v1, p2, v2):
|
def berechne_schnittpunkt(p1, v1, p2, v2):
|
||||||
@@ -50,34 +50,32 @@ def read_input(filename:str)->list[list[int]]:
|
|||||||
if line == "":
|
if line == "":
|
||||||
continue
|
continue
|
||||||
else:
|
else:
|
||||||
pat = r'^(-?\d+), (-?\d+), -?\d+ \@ (-?\d+), (-?\d+), -?\d+$'
|
pat = r'^(-?\d+), +(-?\d+), +-?\d+ +\@ +(-?\d+), +(-?\d+), +-?\d+$'
|
||||||
match = re.match(pat, line)
|
match = re.match(pat, line)
|
||||||
if match:
|
result.append(list(map(int,[match.group(1), match.group(2), match.group(3), match.group(4)])))
|
||||||
result.append(list(map(int,[match.group(1), match.group(2), match.group(3), match.group(4)])))
|
|
||||||
input_file.close()
|
input_file.close()
|
||||||
return result
|
return result
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
sol = 0
|
sol = 0
|
||||||
''' # Beispielaufruf
|
''' # Beispielaufruf
|
||||||
p_1 = (18, 19)
|
p_1 = (18, 19)
|
||||||
v_1 = (-1, -1)
|
v_1 = (-1, -1)
|
||||||
p_2 = (12, 31)
|
p_2 = (12, 31)
|
||||||
v_2 = (-1, -2)
|
v_2 = (-1, -2)
|
||||||
schnitt_punkt = berechne_schnittpunkt(p_1, v_1, p_2, v_2)
|
schnitt_punkt = berechne_schnittpunkt(p_1, v_1, p_2, v_2)
|
||||||
if schnitt_punkt:
|
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:
|
else:
|
||||||
print("Die Strahlen schneiden sich nicht.")
|
print("Die Strahlen schneiden sich nicht.")
|
||||||
'''
|
'''
|
||||||
|
|
||||||
d = read_input(file)
|
d = read_input(file)
|
||||||
for i in range(len(d)):
|
for i in range(len(d)):
|
||||||
for j in range(i, len(d)):
|
for j in range(i+1, 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]))
|
s = berechne_schnittpunkt((d[i][0],d[i][1]), (d[i][2],d[i][3]),
|
||||||
if s:
|
(d[j][0],d[j][1]), (d[j][2],d[j][3]))
|
||||||
print(s[0],s[1])
|
|
||||||
if s and XY_MIN < s[0] < XY_MAX and XY_MIN < s[1] < XY_MAX:
|
if s and XY_MIN < s[0] < XY_MAX and XY_MIN < s[1] < XY_MAX:
|
||||||
print("------------", s[0], s[1])
|
|
||||||
sol += 1
|
sol += 1
|
||||||
print(f"Solution Part1: {sol}")
|
print(f"Solution Part1: {sol}")
|
||||||
print(f'Runtime: {time()-start_time:.2f} s')
|
print(f'Runtime: {time()-start_time:.2f} s')
|
||||||
|
|||||||
Reference in New Issue
Block a user