Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
2 points inside solution in Clear category for Counting Tiles by CDG.Axel
def checkio(radius):
inside, partly, n = 0, 0, int(radius + 1 - 1e-9)
for x in range(n):
for y in range(n):
parts = [(x + dx) ** 2 + (y + dy) ** 2 <= radius ** 2 for dx, dy in ((0, 0), (1, 1))]
inside += all(parts)
partly += any(parts)
return [4 * inside, 4 * (partly - inside)]
#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"
Nov. 14, 2021
Comments: