aboutsummaryrefslogtreecommitdiff
path: root/challenge-251/sgreen/python/ch-1.py
diff options
context:
space:
mode:
authorMohammad Sajid Anwar <Mohammad.Anwar@yahoo.com>2024-01-14 12:18:28 +0000
committerGitHub <noreply@github.com>2024-01-14 12:18:28 +0000
commita032c84e79bf314d6118fcd6ebb15fdcc63c8998 (patch)
tree92dc95c7aa0b288fe730fde93d3fde3899ee09f7 /challenge-251/sgreen/python/ch-1.py
parent53668b050d994a10fdebda5fbafba13ce8f74bc5 (diff)
parent74305a8889574d47d371f158170892e1697fa13f (diff)
downloadperlweeklychallenge-club-a032c84e79bf314d6118fcd6ebb15fdcc63c8998.tar.gz
perlweeklychallenge-club-a032c84e79bf314d6118fcd6ebb15fdcc63c8998.tar.bz2
perlweeklychallenge-club-a032c84e79bf314d6118fcd6ebb15fdcc63c8998.zip
Merge pull request #9390 from simongreen-net/master
Simon's solution to challenge 251
Diffstat (limited to 'challenge-251/sgreen/python/ch-1.py')
-rwxr-xr-xchallenge-251/sgreen/python/ch-1.py25
1 files changed, 25 insertions, 0 deletions
diff --git a/challenge-251/sgreen/python/ch-1.py b/challenge-251/sgreen/python/ch-1.py
new file mode 100755
index 0000000000..258ef4da0d
--- /dev/null
+++ b/challenge-251/sgreen/python/ch-1.py
@@ -0,0 +1,25 @@
+#!/usr/bin/env python3
+
+import sys
+
+
+def main(ints):
+ solution = 0
+ half = len(ints) // 2
+
+ # If we have an odd number of integers, use the middle value
+ if len(ints) % 2 == 1:
+ solution += ints[half]
+
+ # Combine the concatenation of the remaining integers, starting with first
+ # and last, then second and second last, and so on.
+ for i in range(half):
+ solution += int(str(ints[i]) + str(ints[-1-i]))
+
+ print(solution)
+
+
+if __name__ == '__main__':
+ # Convert input into integers
+ array = [int(n) for n in sys.argv[1:]]
+ main(array)