Skip to content

Instantly share code, notes, and snippets.

@jubishop
Created June 6, 2019 20:12
Show Gist options
  • Save jubishop/17f7003718e8b1ac3e1a36bfcdcb1944 to your computer and use it in GitHub Desktop.
Save jubishop/17f7003718e8b1ac3e1a36bfcdcb1944 to your computer and use it in GitHub Desktop.
class Point
attr_accessor :x, :y
def initialize(x, y)
@x = x
@y = y
end
def ==(point)
return (@x == point.x and @y == point.y)
end
def slope(point)
if (@x == point.x)
return Float::INFINITY
else
return Rational(point.y - @y, point.x - @x)
end
end
end
def is_boomerang(points)
p1, p2, p3 = *points.map {|point| Point.new(point[0], point[1])}
if (p1 == p2 or p2 == p3 or p1 == p3)
return false
end
return p1.slope(p2) != p2.slope(p3)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment