Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Uncategorized category for Counting Tiles by coells
from math import ceil, hypot
def checkio(r):
part = 4 * sum((hypot(x, y) <= r) + (hypot(x + 1, y + 1) <= r) * 1j for x in range(ceil(r)) for y in range(ceil(r)))
return [part.imag, part.real - part.imag]
#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"
April 5, 2014
Comments: