Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
s pervogo raza solution in Clear category for Counting Tiles by lechrudik
import math
def checkio(radius):
def calc(x1, y1, x2, y2):
dist = math.sqrt((x2 - x1) ** 2 + (y2 - y1) ** 2)
return dist
border = [0, 0], [0, -1], [-1, -1], [-1, 0]
solid, partial = 0, 0
for x in range(5, -5, -1):
for y in range(5, -5, -1):
if all([calc(0, 0, x + dx, y + dy) < radius for dx, dy in border]):
solid += 1
elif any([calc(0, 0, x + dx, y + dy) < radius for dx, dy in border]):
partial += 1
return [solid, partial]
#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 18, 2021
Comments: