Created
August 22, 2013 19:06
-
-
Save MasterAlish/6311422 to your computer and use it in GitHub Desktop.
Solution for "sunloverz / gist:6309925" on ruby
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 RectangularGrid | |
def countRectangles(n,m) | |
sum = 0 | |
for i_n in 1..n | |
for i_m in 1..m | |
if i_m != i_n | |
sum = sum + (m-i_m+1)*(n-i_n+1) | |
end | |
end | |
end | |
return sum | |
end | |
end | |
r = Rect.new | |
puts r.countRectangles(3,3) | |
puts r.countRectangles(2,5) | |
puts r.countRectangles(592,964) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment