diff --git a/ruby/2013-detect-squares.rb b/ruby/2013-detect-squares.rb new file mode 100644 index 000000000..ac390954b --- /dev/null +++ b/ruby/2013-detect-squares.rb @@ -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 \ No newline at end of file