Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Uncategorized category for Counting Tiles by sleepyone
from math import ceil
def dist(x,y):
return x*x + y*y
def checkio(radius):
sq = radius ** 2
r = int(ceil(radius))
"""count tiles"""
partial, full = 0, 0
for i in range(r):
for j in range(r):
if dist(i,j) < sq:
if dist(i+1, j+1) <= sq:
partial, full = partial, full + 1
else:
partial, full = partial + 1, full
return [full * 4, partial * 4]
if __name__ == '__main__':
assert checkio(2) == [4, 12], "First, N=2"
assert checkio(3) == [16, 20], "Second, N=3"
assert checkio(2.1) == [4, 20], "Third, N=2.1"
assert checkio(2.5) == [12, 20], "Fourth, N=2.5"
Nov. 6, 2012
Comments: