forked from KenMercusLai/checkio
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Counting tiles.py
28 lines (23 loc) · 988 Bytes
/
Counting tiles.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
from math import ceil, hypot
def getMaxAndMinDistances(radius):
radius = int(ceil(radius))
distances = []
for row in range(radius):
for col in range(radius):
temp = [hypot(row - radius, col - radius), hypot(row - radius, radius - col - 1),
hypot(radius - row - 1, radius - col), hypot(radius - row - 1, radius - col - 1)]
distances.append((min(temp), max(temp)))
return distances
def checkio(radius):
distances = getMaxAndMinDistances(radius)
solid = len(filter(lambda x: x[1] < radius, distances))
partial = len(filter(lambda x: x[1] > radius > x[0], distances))
"""count tiles"""
return [solid * 4, partial * 4]
# 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"