Passed
Push — master ( fc0d08...7f4779 )
by Ken M.
01:05
created

counting_tiles.checkio()   A

Complexity

Conditions 3

Size

Total Lines 6
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 5
nop 1
dl 0
loc 6
rs 10
c 0
b 0
f 0
1
from math import ceil, hypot
2
3
4
def getMaxAndMinDistances(radius):
5
    radius = int(ceil(radius))
6
    distances = []
7
    for row in range(radius):
8
        for col in range(radius):
9
            temp = [
10
                hypot(row - radius, col - radius),
11
                hypot(row - radius, radius - col - 1),
12
                hypot(radius - row - 1, radius - col),
13
                hypot(radius - row - 1, radius - col - 1),
14
            ]
15
            distances.append((min(temp), max(temp)))
16
    return distances
17
18
19
def checkio(radius):
20
    distances = getMaxAndMinDistances(radius)
21
    solid = len(list(filter(lambda x: x[1] < radius, distances)))
22
    partial = len(list(filter(lambda x: x[1] > radius > x[0], distances)))
23
    """count tiles"""
24
    return [solid * 4, partial * 4]
25
26
27
# These "asserts" using only for self-checking and not necessary for
28
# auto-testing
29
if __name__ == '__main__':
30
    assert checkio(2) == [4, 12], "N=2"
31
    assert checkio(3) == [16, 20], "N=3"
32
    assert checkio(2.1) == [4, 20], "N=2.1"
33
    assert checkio(2.5) == [12, 20], "N=2.5"
34