diff options
| author | Simon Green <mail@simon.green> | 2024-01-21 21:43:03 +1100 |
|---|---|---|
| committer | Simon Green <mail@simon.green> | 2024-01-21 21:43:03 +1100 |
| commit | 50431906f587a0d8622ac4714edb64e612facc11 (patch) | |
| tree | 8cd837b23558d98378ebd5219df6028b4f0b6a23 /challenge-252/sgreen/python/ch-1.py | |
| parent | 7efb373bb9adffa79f84825217015835805298b5 (diff) | |
| download | perlweeklychallenge-club-50431906f587a0d8622ac4714edb64e612facc11.tar.gz perlweeklychallenge-club-50431906f587a0d8622ac4714edb64e612facc11.tar.bz2 perlweeklychallenge-club-50431906f587a0d8622ac4714edb64e612facc11.zip | |
Simon's solution to challenge 252
Diffstat (limited to 'challenge-252/sgreen/python/ch-1.py')
| -rwxr-xr-x | challenge-252/sgreen/python/ch-1.py | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/challenge-252/sgreen/python/ch-1.py b/challenge-252/sgreen/python/ch-1.py new file mode 100755 index 0000000000..68b87cbc81 --- /dev/null +++ b/challenge-252/sgreen/python/ch-1.py @@ -0,0 +1,21 @@ +#!/usr/bin/env python3 + +import sys + + +def main(ints): + solution = 0 + length = len(ints) + + for pos in range(length): + if length % (pos+1) == 0: + # This is a special number. Add its square to the solution + solution += ints[pos] ** 2 + + print(solution) + + +if __name__ == '__main__': + # Convert input into integers + array = [int(n) for n in sys.argv[1:]] + main(array) |
