Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Clear category for Counting Tiles by tobytobytoby
import math
def checkio(r):
solid = 0
for x in range(1,int(r)+1): #how many solid in each sector
y = (r**2 - x**2)**0.5 #equation of a circle
solid += int(y) #rounds down to exlude partials
all = 0
for x in range(0,int(r)+1): #how many total in each sector
y = (r**2 - x**2)**0.5
all += math.ceil(y) #rounds up to include partials
return [solid*4,(all-solid)*4] #there a 4 identicle sectors to each circle
#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"
July 4, 2014