aboutsummaryrefslogtreecommitdiff
path: root/challenge-252/lubos-kolouch/python/ch-1.py
diff options
context:
space:
mode:
Diffstat (limited to 'challenge-252/lubos-kolouch/python/ch-1.py')
-rw-r--r--challenge-252/lubos-kolouch/python/ch-1.py18
1 files changed, 18 insertions, 0 deletions
diff --git a/challenge-252/lubos-kolouch/python/ch-1.py b/challenge-252/lubos-kolouch/python/ch-1.py
new file mode 100644
index 0000000000..ab82a6eb2d
--- /dev/null
+++ b/challenge-252/lubos-kolouch/python/ch-1.py
@@ -0,0 +1,18 @@
+#!/usr/bin/env python
+
+
+def sum_of_special_squares(ints: list[int]) -> int:
+ """
+ Calculates the sum of squares of all special elements in the array.
+ A special element is defined as one whose 1-based index divides the length of the array.
+
+ :param ints: List of integers
+ :return: Sum of squares of special elements
+ """
+ n = len(ints)
+ return sum(ints[i - 1] ** 2 for i in range(1, n + 1) if n % i == 0)
+
+
+# Tests
+assert sum_of_special_squares([1, 2, 3, 4]) == 21
+assert sum_of_special_squares([2, 7, 1, 19, 18, 3]) == 63