Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Uncategorized category for Counting Tiles by slygoblin
import math
def checkio(radius):
tiles = 0
whole = 0
for i in range(math.ceil(radius)):
for j in range(math.ceil(radius)):
if dis(i+1, j+1)<=radius:
tiles += 1
if dis(i, j)<=radius:
whole += 1
return [4*tiles, 4*(whole - tiles)]
def dis(x, y):
return math.sqrt(x*x + y*y)
#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. 15, 2015