aboutsummaryrefslogtreecommitdiff
path: root/challenge-240/ianrifkin/python
diff options
context:
space:
mode:
authoririfkin <ianrifkin@ianrifkin.com>2023-10-28 17:53:30 -0400
committeririfkin <ianrifkin@ianrifkin.com>2023-10-28 17:53:30 -0400
commit5d10a6e13bb7823cc671eec3bd682cef6bed5ef7 (patch)
treeab09b937040c61dd44773fe35b32f9265bd00cdd /challenge-240/ianrifkin/python
parent67310476fd1daa9d74365ca666f4f6d9a0932d50 (diff)
downloadperlweeklychallenge-club-5d10a6e13bb7823cc671eec3bd682cef6bed5ef7.tar.gz
perlweeklychallenge-club-5d10a6e13bb7823cc671eec3bd682cef6bed5ef7.tar.bz2
perlweeklychallenge-club-5d10a6e13bb7823cc671eec3bd682cef6bed5ef7.zip
solutions in perl, python, and raku. and a README of a blog post.
Diffstat (limited to 'challenge-240/ianrifkin/python')
-rw-r--r--challenge-240/ianrifkin/python/ch-1.py27
-rw-r--r--challenge-240/ianrifkin/python/ch-2.py19
2 files changed, 46 insertions, 0 deletions
diff --git a/challenge-240/ianrifkin/python/ch-1.py b/challenge-240/ianrifkin/python/ch-1.py
new file mode 100644
index 0000000000..a7e88fddd5
--- /dev/null
+++ b/challenge-240/ianrifkin/python/ch-1.py
@@ -0,0 +1,27 @@
+#!/usr/local/bin/python3
+
+# You are given an array of strings and a check string.
+# Write a script to find out if the check string is the acronym of the words in the given array.
+
+def check_acronym (acronym, words):
+ real_acronym = ''
+ for word in words:
+ real_acronym += word[0]
+ print(acronym.upper() == real_acronym.upper())
+
+# Example 1
+words = ("Perl", "Python", "Pascal")
+acronym = "ppp"
+check_acronym(acronym, words)
+
+# Example 2
+words = ("Perl", "Raku")
+acronym = "rp"
+check_acronym(acronym, words)
+
+# Example 3
+words = ("Oracle", "Awk", "C")
+acronym = "oac"
+check_acronym(acronym, words)
+
+
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)