Created
August 22, 2012 01:01
-
-
Save alaingilbert/3421059 to your computer and use it in GitHub Desktop.
How many squares question...
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
# http://www.quora.com/Puzzle-and-Trick-Questions/How-many-squares-are-in-this-picture | |
def get_square_count(length): | |
squares = 0 | |
nb_nodes = length ** 2 | |
for i in range(nb_nodes): | |
tmp = i + 1 | |
while tmp % 5 != 0 and tmp + ((tmp - i) * length) < nb_nodes: | |
tmp += 1 | |
squares += 1 | |
return squares | |
print 'Response: %s' % (get_square_count(5) + 2 * get_square_count(3)) | |
# Response: 40 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment