aboutsummaryrefslogtreecommitdiff
path: root/challenge-240/ianrifkin/python/ch-2.py
diff options
context:
space:
mode:
Diffstat (limited to 'challenge-240/ianrifkin/python/ch-2.py')
-rw-r--r--challenge-240/ianrifkin/python/ch-2.py19
1 files changed, 19 insertions, 0 deletions
diff --git a/challenge-240/ianrifkin/python/ch-2.py b/challenge-240/ianrifkin/python/ch-2.py
new file mode 100644
index 0000000000..1fe9ec38f7
--- /dev/null
+++ b/challenge-240/ianrifkin/python/ch-2.py
@@ -0,0 +1,19 @@
+#!/usr/local/bin/python3
+
+# You are given an array of integers.
+# Write a script to create an array such that new[i] = old[old[i]] where 0 <= i < new.length.
+
+def create_new_array (ints):
+ new_ints = []
+ # Loop through old array to create new array
+ for i, item in enumerate(ints):
+ new_ints.insert(i, ints[ints[i]])
+ print(new_ints)
+
+# Example 1
+ints = (0, 2, 1, 5, 3, 4)
+create_new_array(ints)
+
+# Example 2
+ints = (5, 0, 1, 2, 3, 4)
+create_new_array(ints)