From 5d10a6e13bb7823cc671eec3bd682cef6bed5ef7 Mon Sep 17 00:00:00 2001 From: irifkin Date: Sat, 28 Oct 2023 17:53:30 -0400 Subject: solutions in perl, python, and raku. and a README of a blog post. --- challenge-240/ianrifkin/python/ch-2.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 challenge-240/ianrifkin/python/ch-2.py (limited to 'challenge-240/ianrifkin/python/ch-2.py') 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) -- cgit