-
-
Save jubishop/17f7003718e8b1ac3e1a36bfcdcb1944 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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