diff options
| author | Mohammad Sajid Anwar <Mohammad.Anwar@yahoo.com> | 2024-01-21 17:12:53 +0000 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-01-21 17:12:53 +0000 |
| commit | ce89cdf807f253b29c4206ed706c9b8d61110c66 (patch) | |
| tree | ac716c082c16fe125f1e98472ade890e10ce9222 /challenge-252/sgreen/python | |
| parent | 8fabfef95159d246eaad5fd7a7c2922d38e48b48 (diff) | |
| parent | 50431906f587a0d8622ac4714edb64e612facc11 (diff) | |
| download | perlweeklychallenge-club-ce89cdf807f253b29c4206ed706c9b8d61110c66.tar.gz perlweeklychallenge-club-ce89cdf807f253b29c4206ed706c9b8d61110c66.tar.bz2 perlweeklychallenge-club-ce89cdf807f253b29c4206ed706c9b8d61110c66.zip | |
Merge pull request #9432 from simongreen-net/master
Simon's solution to challenge 252
Diffstat (limited to 'challenge-252/sgreen/python')
| -rwxr-xr-x | challenge-252/sgreen/python/ch-1.py | 21 | ||||
| -rwxr-xr-x | challenge-252/sgreen/python/ch-2.py | 24 |
2 files changed, 45 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) diff --git a/challenge-252/sgreen/python/ch-2.py b/challenge-252/sgreen/python/ch-2.py new file mode 100755 index 0000000000..745338701a --- /dev/null +++ b/challenge-252/sgreen/python/ch-2.py @@ -0,0 +1,24 @@ +#!/usr/bin/env python3 + +import sys + + +def main(n): + solution = [] + half = n // 2 + + # If we have an odd number, add a zero + if n % 2 == 1: + solution = [0] + + for i in range(half): + # Add a pair of numbers + solution.insert(0, -i-1) + solution.append(i+1) + + print(*solution, sep=', ') + + +if __name__ == '__main__': + # Convert input into integers + main(int(sys.argv[1])) |
