aboutsummaryrefslogtreecommitdiff
path: root/challenge-160/lubos-kolouch/python/ch-2.py
blob: dd95012303d9f531184fe90abdc96959ba447033 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
""" Challenge 160 Task 2 """


def get_eq_index(what: list) -> int:
    """Get the Equilibrium Index"""

    elem_count = len(what)

    for i in range(1, elem_count - 1):
        if sum(what[0:i]) == sum(what[i + 1 : elem_count]):
            return i

    return -1


assert get_eq_index([1, 3, 5, 7, 9]) == 3
assert get_eq_index([1, 2, 3, 4, 5]) == -1
assert get_eq_index([2, 4, 2]) == 1

assert get_eq_index([2]) == -1