Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Clear category for Counting Tiles by jantechner
def distance(x, y):
return (x**2 + y**2)**0.5
def checkio(n):
orgn = n
if n - round(n) != 0:
n = round(n+1)
whole = 0
partial = 0
for i in range(0,n):
for j in range(0, n):
if distance(i,j)<=orgn and distance(i+1, j+1)<=orgn :
whole+=1
elif distance(i,j)<=orgn and distance(i+1, j+1)>orgn :
partial += 1
return [whole*4, partial*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"
Dec. 1, 2016