Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
check corners solution in Clear category for Counting Tiles by gtff
from math import ceil
def checkio(radius):
"""count tiles"""
solid = 0
partial = 0
a = ceil(radius)
for x in range(a):
for y in range(a):
if (x + 1)**2 + (y + 1)**2 <= radius**2:
## "outer" corner in circle
solid += 1
elif x**2 + y**2 <= radius**2:
## "inner" corner in circle
partial += 1
## we counted one quadrant only, so multiply by 4
return [solid * 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"
Oct. 26, 2020
Comments: