Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Clear category for Counting Tiles by tom-tom
def checkio(radius):
"""count tiles"""
w, p = 0, 0
for i in range(5):
for j in range(5):
if i ** 2 + j ** 2 < radius ** 2:
if (i + 1) ** 2 + (j + 1) ** 2 <= radius ** 2:
w += 1
else:
p += 1
return [w * 4, p * 4]
#These "asserts" using only for self-checking and not necessary for auto-testing
if __name__ == '__main__':
assert checkio(2) == [4, 12], "N=2"
assert checkio(3) == [16, 20], "N=3"
assert checkio(2.1) == [4, 20], "N=2.1"
assert checkio(2.5) == [12, 20], "N=2.5"
Oct. 11, 2016