Selecting mid points..

Hii.. I am facing a problem here.. I have a number of points, let say 20. Now some of them have their any two coordinates(x and y OR y and z OR x and z) same and some of them have only one coordinate same. So basically I nee to find such points and find their mid  points .

So what can I do is run two for loops, one inside other,  for 1st point, check the condition with other 19 points, if condition satisfies, then find the midpoint and store it.

There might be two conditions 1.points with two same coordinates 2. points with one same coordinate in order to lie the two points on a line.  

I dont understand how to write an algo for the problem.. Any help..

SolidworksSketching