using System.Collections.Generic;
public static void Main()
var result = new Ray().solution(new Point2D[] {
new Point2D { x = -1, y = -2 },
new Point2D { x = 1, y = 2 },
new Point2D { x = 2, y = 4 },
Console.WriteLine(result);
public int solution(Point2D[] arr)
HashSet<Point2D> toSkip = new HashSet<Point2D>();
int resultedCountOfRays = 0;
for (var i = 0; i < arr.Length; i++)
if (arr[i].x == 0 && arr[i].y == 0)
if (!toSkip.Contains(arr[i]))
var currentItem = arr[i];
for (var j = i+1; j < arr.Length; j++)
var potentialItem = arr[j];
if (IsInFXRange(currentItem.x, currentItem.y, potentialItem.x, potentialItem.y))
toSkip.Add(potentialItem);
return resultedCountOfRays;
private bool IsInFXRange(long vx1, long vy1, long xx, long yy)
return ((y1 - y2) * x) + ((x2 - x1) * y) + (x1 * y2 - x2 * y1) == 0;