aboutsummaryrefslogtreecommitdiff
path: root/challenge-252
diff options
context:
space:
mode:
authorMohammad Sajid Anwar <Mohammad.Anwar@yahoo.com>2024-01-16 19:59:51 +0000
committerGitHub <noreply@github.com>2024-01-16 19:59:51 +0000
commitfcfba54740e333884b35285e04781121e3ca20d8 (patch)
treee72e4d9571efba319583d74b521234b6c2054cd7 /challenge-252
parent12a3656241b574e12bdf9470051766e7a0fa8375 (diff)
parent7a176cccf4b2419ebd55d54d610de24fe00ce9e3 (diff)
downloadperlweeklychallenge-club-fcfba54740e333884b35285e04781121e3ca20d8.tar.gz
perlweeklychallenge-club-fcfba54740e333884b35285e04781121e3ca20d8.tar.bz2
perlweeklychallenge-club-fcfba54740e333884b35285e04781121e3ca20d8.zip
Merge pull request #9416 from oWnOIzRi/week252
add solution week 252 task 1 in python
Diffstat (limited to 'challenge-252')
-rw-r--r--challenge-252/steven-wilson/python/ch-01.py23
1 files changed, 23 insertions, 0 deletions
diff --git a/challenge-252/steven-wilson/python/ch-01.py b/challenge-252/steven-wilson/python/ch-01.py
new file mode 100644
index 0000000000..1beb425462
--- /dev/null
+++ b/challenge-252/steven-wilson/python/ch-01.py
@@ -0,0 +1,23 @@
+#!/usr/bin/env python3
+
+
+def special_numbers(*integers):
+ '''Given an array of integers, find the sum of the squares of all special
+ elements of the array.
+
+ An element $int[i] of @ints is called special if i divides n, i.e.
+ n % i == 0. Where n is the length of the given array. The array is
+ 1-indexed.
+ >>> special_numbers(1, 2, 3, 4)
+ 21
+ >>> special_numbers(2, 7, 1, 19, 18, 3)
+ 63
+ '''
+ len_i = len(integers)
+ return sum(integers[x-1] * integers[x-1] for x in range(1, len_i+1) if len_i % x == 0)
+
+
+if __name__ == "__main__":
+ import doctest
+
+ doctest.testmod()