# Day 24, Part 1

unknown
python
8 months ago
1.3 kB
18
Indexable
Never
```from fractions import Fraction as frac
from numpy import sign
from math import inf
f=open("input.txt","r")
vel,cor=[],[]
for line in f:
line=line.replace("\n","").replace("@",",").replace(" ","").split(",")
cor.append([int(line[0]),int(line[1]),int(line[2])])
vel.append([int(line[3]),int(line[4]),int(line[5])])
f.close()

def cross(a,b):
x_1, y_1 = cor[a][0], cor[a][1]
x_2, y_2 = cor[b][0], cor[b][1]
m_1 = frac(vel[a][1],vel[a][0])
m_2 = frac(vel[b][1],vel[b][0])
if m_1 == m_2:
if x_1 == x_2:
return[200000000000001,200000000000001]
return [inf,inf]
x_3 = frac(y_2 - m_2 * x_2 - y_1 + m_1 * x_1,m_1-m_2)
y_3 = m_1 * x_3 + y_1 - m_1*x_1
if x_3*sign(vel[a][0]) < sign(vel[a][0]) * x_1:
return[inf,inf]
if x_3*sign(vel[b][0]) < sign(vel[b][0]) * x_2:
return[inf,inf]
return [x_3,y_3]

counter = 0
x_left,y_left = 200000000000000,200000000000000
x_right,y_right=400000000000000,400000000000000

for i in range(len(cor)):
for j in range(i+1,len(cor)):
punkt = cross(i,j)
if punkt[0] - x_left >= 0 and punkt[0] - x_right <= 0:
if punkt[1] -y_left >= 0 and punkt[1] - y_right <= 0:
counter+=1
print(counter)  ```