Skip to content

Commit

Permalink
Ruby Solution for detecting squares
Browse files Browse the repository at this point in the history
  • Loading branch information
saip7795 committed Jan 12, 2023
1 parent 6b15c8f commit 62b2b72
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions ruby/2013-detect-squares.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
class DetectSquares
def initialize()
@points_count = Hash.new(0)
@points = []
end


def add(point)
@points_count[point] +=1
@points.append(point)
end

def count(point)
result = 0
px = point[0]
py = point[1]

@points.each do |p|
next if (((py-p[1]).abs != (px-p[0]).abs) || (p[0]==px) ||(p[1]==py))
result += @points_count[[p[0],py]] * @points_count[[px,p[1]]]
end

return result

end


end

0 comments on commit 62b2b72

Please sign in to comment.