aboutsummaryrefslogtreecommitdiff
path: root/challenge-264/packy-anderson/python/ch-2.py
diff options
context:
space:
mode:
Diffstat (limited to 'challenge-264/packy-anderson/python/ch-2.py')
-rwxr-xr-xchallenge-264/packy-anderson/python/ch-2.py36
1 files changed, 36 insertions, 0 deletions
diff --git a/challenge-264/packy-anderson/python/ch-2.py b/challenge-264/packy-anderson/python/ch-2.py
new file mode 100755
index 0000000000..2b0fecb467
--- /dev/null
+++ b/challenge-264/packy-anderson/python/ch-2.py
@@ -0,0 +1,36 @@
+#!/usr/bin/env python
+
+def targetArray(source, indices):
+ target = []
+ explain = []
+
+ for i in range(len(indices)):
+ target.insert(indices[i], source[i])
+ explain.append([
+ source[i], indices[i], target.copy()
+ ])
+ return target, explain
+
+def comma_join(arr):
+ return ', '.join(map(lambda i: str(i), arr))
+
+def solution(source, indices):
+ print(f'Input: @source = ({comma_join(source)})')
+ print(f' @indices = ({comma_join(indices)})')
+ output, explain = targetArray(source, indices)
+ print(f'Output: ({comma_join(output)})\n')
+ print('@source @indices @target')
+ for row in explain:
+ print(
+ f'{row[0]} {row[1]} ' +
+ f'({comma_join(row[2])})'
+ )
+
+print('Example 1:')
+solution([0, 1, 2, 3, 4], [0, 1, 2, 2, 1])
+
+print('\nExample 2:')
+solution([1, 2, 3, 4, 0], [0, 1, 2, 3, 0])
+
+print('\nExample 3:')
+solution([1], [0]) \ No newline at end of file