# Created by Egor Kostan.
# GitHub: https://github.com/ikostan
# LinkedIn: https://www.linkedin.com/in/egor-kostan/
import math
[docs]def easy_line(n: int) -> int:
"""
The function will take n (with: n>= 0) as parameter
and will return the sum of the squares of the binomial
coefficients on line n.
:param n: the line number (with: n>= 0)
:return:
"""
if n < 0:
raise ValueError('ERROR: invalid n ({}) value. n must be >= 0')
if n == 0:
return 1
result = 0
i = 0
for row in range(n - 1, 2 * n):
result += calc_combination_per_row_item(row, i)
i += 1
return result
[docs]def calc_combination_per_row_item(row: int, i: int) -> int:
"""
Generates a specific combination from Pascal's Triangle row by specified index
:param row: row
:param i: index
:return:
"""
combination = int(math.factorial(row)) // (int(math.factorial(i)) * int(math.factorial(row - i)))
# print(f'\n{row}! / ({i}! * ({row} - {i})!) = {combination}') # debug only
return combination