Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
Pythagorean counter solution in Uncategorized category for Counting Tiles by papernode
import math
def checkio(data):
radius = data
radius_2 = radius * radius
# For one quarter circle, determine how many tiles are covered:
solid = 0
for x in range(1, math.ceil(radius)):
solid += math.floor(math.sqrt(radius_2 - x * x))
solid *= 4
# Then determine how many tiles are at least partially covered:
solid_or_partial = 0
for x in range(0, math.ceil(radius)):
solid_or_partial += math.ceil(math.sqrt(radius_2 - x * x))
solid_or_partial *= 4
return solid, solid_or_partial - solid
#
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"
Dec. 23, 2012