...
Secondly, I had seen this problem posed in multiple places and a solution in perl for the "lines2" which did not seem to work for "lines1".(my mistake, did not use enough points in the loops)
Problem: Count all triangles in the diagram.
Solution: select 3 points shared by 3 different lines
...