Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
Easy and fun solution in Clear category for Counting Tiles by mohamedsleymi2016
from math import sqrt
cal = lambda x:32 if x>=sqrt(13) else 24 if x >=sqrt(10) else 16 if x >=(2*sqrt(2)) else 12 if x>=sqrt(5) else 4 if x>=sqrt(2) else 4*(int((x*x)/2))
def checkio(n):
"""count tiles"""
if (n==4):
return [32,28]
if int(n)==n:
solid = (2*(n-1))*(2*(n-1))
partial = 4*n*n-solid
return [solid, partial]
return [cal(n),checkio(int(n)+1)[1]]
#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"
May 18, 2021
Comments: