Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Clear category for Counting Tiles by tokyoamado
from math import sqrt, ceil
def checkio(radius):
d = [incircle(radius, cell) for cell in diag(radius)]
u = [incircle(radius, cell) for cell in under(radius)]
return [
d.count('Perfect') * 4 + u.count('Perfect') * 8,
d.count('Partial') * 4 + u.count('Partial') * 8
]
diag = lambda radius: [(x, x) for x in range(ceil(radius / sqrt(2)))]
under = lambda radius: [(x, y) for x in range(1, ceil(radius)) for y in range(x)]
def incircle(radius, cell):
x, y = cell
corners = [(x, y), (x + 1, y), (x, y + 1), (x + 1, y + 1)]
judge = [x ** 2 + y ** 2 <= radius ** 2 for x, y in corners]
if all(judge):
return 'Perfect'
elif any(judge):
return 'Partial'
else:
return 'None'
Jan. 15, 2018
Comments: