Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit62b2b72

Browse files
committed
Ruby Solution for detecting squares
1 parent6b15c8f commit62b2b72

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

‎ruby/2013-detect-squares.rb

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
classDetectSquares
2+
definitialize()
3+
@points_count=Hash.new(0)
4+
@points=[]
5+
end
6+
7+
8+
defadd(point)
9+
@points_count[point] +=1
10+
@points.append(point)
11+
end
12+
13+
defcount(point)
14+
result=0
15+
px=point[0]
16+
py=point[1]
17+
18+
@points.eachdo |p|
19+
nextif(((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+
end
22+
23+
returnresult
24+
25+
end
26+
27+
28+
end

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp