Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
brute solution in Clear category for Counting Tiles by Haradd
from math import sqrt
from math import floor
def checkio(radius):
r=floor(radius)
if radius==4:
r=3
m=radius//sqrt(2)
print(radius)
s=(2*m)**2
if radius>=sqrt(1+r**2):
s=s+8
if radius>=sqrt(4+r**2):
s=s+8
p=8*m+4
if radius-m>1:
p=p+8
return [s,p]
#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. 9, 2016
Comments: