We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 6b15c8f commit 62b2b72Copy full SHA for 62b2b72
ruby/2013-detect-squares.rb
@@ -0,0 +1,28 @@
1
+class DetectSquares
2
+ def initialize()
3
+ @points_count = Hash.new(0)
4
+ @points = []
5
+ end
6
+
7
8
+ def add(point)
9
+ @points_count[point] +=1
10
+ @points.append(point)
11
12
13
+ def count(point)
14
+ result = 0
15
+ px = point[0]
16
+ py = point[1]
17
18
+ @points.each do |p|
19
+ next if (((py-p[1]).abs != (px-p[0]).abs) || (p[0]==px) ||(p[1]==py))
20
+ result += @points_count[[p[0],py]] * @points_count[[px,p[1]]]
21
22
23
+ return result
24
25
26
27
28
+end
0 commit comments