Here is my code
I thought to solve this using mirror image so I create all 8 mirror of given position and then try to find distance between guard_position in every mirror with some constrain as per question but something is went wrong can you help me?

``````import math
def solution(dimensions, your_position, guard_position, distance):
our_p =[]
our_p.append(your_position)
ux=your_position[0]
uy=your_position[1]+2*(dimensions[1]-your_position[1])
ex = []
ex.append(ux)
ex.append(uy)
our_p.append(ex)

ux=-your_position[0]
uy=your_position[1]+2*(dimensions[1]-your_position[1])
ex = []
ex.append(ux)
ex.append(uy)
our_p.append(ex)

ux=your_position[0] +  2*(dimensions[1]-your_position[1])
uy=your_position[1] +2*(dimensions[1]-your_position[1])
ex = []
ex.append(ux)
ex.append(uy)
our_p.append(ex)

ux=your_position[0] +  2*(dimensions[1]-your_position[1])
uy=-your_position[1] #+2*(dimensions[1]-your_position[1])
ex = []
ex.append(ux)
ex.append(uy)
our_p.append(ex)

ux=-your_position[0] #+  2*(dimensions[1]-your_position[1])
uy=-your_position[1] #+2*(dimensions[1]-your_position[1])
ex = []
ex.append(ux)
ex.append(uy)
our_p.append(ex)

dx=your_position[0]
dy=-your_position[1]
ex = []
ex.append(dx)
ex.append(dy)
our_p.append(ex)

ly=your_position[1]
lx=-your_position[0] #-2*(dimensions[0]-your_position[0])
ex = []
ex.append(lx)
ex.append(ly)
our_p.append(ex)

ly=your_position[1]
lx=your_position[0] + 2*(dimensions[0]-your_position[0])
ex = []
ex.append(lx)
ex.append(ly)
our_p.append(ex)
# print our_p

guard_p=[]
guard_p.append(guard_position)

ux = guard_position[0]
uy=guard_position[1]+2*(dimensions[1]-guard_position[1])
ex = []
ex.append(ux)
ex.append(uy)
guard_p.append(ex)

dx=guard_position[0]
dy=-guard_position[1]
ex = []
ex.append(dx)
ex.append(dy)
guard_p.append(ex)

ly=guard_position[1]
lx=-guard_position[0] #-2*(dimensions[0]-your_position[0])
ex = []
ex.append(lx)
ex.append(ly)
guard_p.append(ex)

ly=guard_position[1]
lx=guard_position[0] + 2*(dimensions[0]-guard_position[0])
ex = []
ex.append(lx)
ex.append(ly)
guard_p.append(ex)

ux=-guard_position[0]
uy=guard_position[1]+2*(dimensions[1]-guard_position[1])
ex = []
ex.append(ux)
ex.append(uy)
guard_p.append(ex)

ux=guard_position[0] +  2*(dimensions[1]-guard_position[1])
uy=guard_position[1] +2*(dimensions[1]-guard_position[1])
ex = []
ex.append(ux)
ex.append(uy)
guard_p.append(ex)

ux=guard_position[0] +  2*(dimensions[1]-guard_position[1])
uy=-guard_position[1] #+2*(dimensions[1]-your_position[1])
ex = []
ex.append(ux)
ex.append(uy)
guard_p.append(ex)

ux=-guard_position[0] #+  2*(dimensions[1]-your_position[1])
uy=-guard_position[1] #+2*(dimensions[1]-your_position[1])
ex = []
ex.append(ux)
ex.append(uy)
guard_p.append(ex)

# print guard_p
count=0

for j in guard_p:
# print i,j
# print(math.sqrt( abs((i[0]-j[0])*(i[0]-j[0])  ) + abs((i[1]-j[1])*(i[1]-j[1]) )))
k=0
no=0
for i in our_p:
if k==0:
k+=1
continue
d1=math.sqrt( abs((your_position[0]-i[0])*(your_position[0]-i[0])  ) + abs((your_position[1]-i[1])*(your_position[1]-i[1]) ) )
d2=math.sqrt( abs((i[0]-j[0])*(i[0]-j[0])  ) + abs((i[1]-j[1])*(i[1]-j[1]) ) )
d3=math.sqrt( abs((your_position[0]-j[0])*(your_position[0]-j[0])  ) + abs((your_position[1]-j[1])*(your_position[1]-j[1]) ) )

if(d3==d1+d2):
# print d1+d2
no=1
continue
if(no==1):
continue
if(math.sqrt( abs((your_position[0]-j[0])*(your_position[0]-j[0])  ) + abs((your_position[1]-j[1])*(your_position[1]-j[1]) ) ) <=distance):
count+=1
# count = count - 2
# print count
return count

print(solution([3,2], [1,1], [2,1], 4))
``````