aboutsummaryrefslogtreecommitdiff
path: root/challenge-251/sgreen/python/ch-1.py
diff options
context:
space:
mode:
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)