aboutsummaryrefslogtreecommitdiff
path: root/challenge-053
diff options
context:
space:
mode:
authorPaulo Custodio <pauloscustodio@gmail.com>2024-09-08 18:11:41 +0100
committerPaulo Custodio <pauloscustodio@gmail.com>2024-09-08 18:11:41 +0100
commit9243782e5c4fe456e60eff6b8565f66af495c4dc (patch)
treea90e557a17a588dff338326ad017acd66f61cf6c /challenge-053
parent470a2b3337f00743a4f35e0d940fdf8f60e737d5 (diff)
downloadperlweeklychallenge-club-9243782e5c4fe456e60eff6b8565f66af495c4dc.tar.gz
perlweeklychallenge-club-9243782e5c4fe456e60eff6b8565f66af495c4dc.tar.bz2
perlweeklychallenge-club-9243782e5c4fe456e60eff6b8565f66af495c4dc.zip
Add Python solution to challenge 053
Diffstat (limited to 'challenge-053')
-rw-r--r--challenge-053/paulo-custodio/perl/ch-2.pl10
-rw-r--r--challenge-053/paulo-custodio/python/ch-1.py42
-rw-r--r--challenge-053/paulo-custodio/python/ch-2.py64
3 files changed, 111 insertions, 5 deletions
diff --git a/challenge-053/paulo-custodio/perl/ch-2.pl b/challenge-053/paulo-custodio/perl/ch-2.pl
index 8eb54e16fa..bb13b9cdb4 100644
--- a/challenge-053/paulo-custodio/perl/ch-2.pl
+++ b/challenge-053/paulo-custodio/perl/ch-2.pl
@@ -9,15 +9,15 @@
#
# The string should follow the following rules:
#
-# ‘a’ can only be followed by ‘e’ and ‘i’.
+# 'a' can only be followed by 'e' and 'i'.
#
-# ‘e’ can only be followed by ‘i’.
+# 'e' can only be followed by 'i'.
#
-# ‘i’ can only be followed by ‘a’, ‘e’, ‘o’, and ‘u’.
+# 'i' can only be followed by 'a', 'e', 'o', and 'u'.
#
-# ‘o’ can only be followed by ‘a’ and ‘u’.
+# 'o' can only be followed by 'a' and 'u'.
#
-# ‘u’ can only be followed by ‘o’ and ‘e’.
+# 'u' can only be followed by 'o' and 'e'.
#
# For example, if the given integer N = 2 then script should print the following
# strings:
diff --git a/challenge-053/paulo-custodio/python/ch-1.py b/challenge-053/paulo-custodio/python/ch-1.py
new file mode 100644
index 0000000000..c323b6f3a8
--- /dev/null
+++ b/challenge-053/paulo-custodio/python/ch-1.py
@@ -0,0 +1,42 @@
+#!/usr/bin/env python3
+
+# Challenge 053
+#
+# TASK #1
+# Rotate Matrix
+# Write a script to rotate the followin matrix by given 90/180/270 degrees
+# clockwise.
+#
+# [ 1, 2, 3 ]
+# [ 4, 5, 6 ]
+# [ 7, 8, 9 ]
+# For example, if you rotate by 90 degrees then expected result should be like
+# below
+#
+# [ 7, 4, 1 ]
+# [ 8, 5, 2 ]
+# [ 9, 6, 3 ]
+
+m = [[ 1, 2, 3 ],
+ [ 4, 5, 6 ],
+ [ 7, 8, 9 ]];
+
+def rotate90(m):
+ return [[ m[2][0], m[1][0], m[0][0] ],
+ [ m[2][1], m[1][1], m[0][1] ],
+ [ m[2][2], m[1][2], m[0][2] ]]
+
+def rotate180(m):
+ return rotate90(rotate90(m))
+
+def rotate270(m):
+ return rotate90(rotate90(rotate90(m)))
+
+def display(m):
+ for row in m:
+ print("[ "+", ".join([str(x) for x in row])+" ]")
+ print("")
+
+display(rotate90(m))
+display(rotate180(m))
+display(rotate270(m))
diff --git a/challenge-053/paulo-custodio/python/ch-2.py b/challenge-053/paulo-custodio/python/ch-2.py
new file mode 100644
index 0000000000..2672f2d84a
--- /dev/null
+++ b/challenge-053/paulo-custodio/python/ch-2.py
@@ -0,0 +1,64 @@
+#!/usr/bin/env python3
+
+# Challenge 053
+#
+# TASK #2
+# Vowel Strings
+# Write a script to accept an integer 1 <= N <= 5 that would print all possible
+# strings of size N formed by using only vowels (a, e, i, o, u).
+#
+# The string should follow the following rules:
+#
+# 'a' can only be followed by 'e' and 'i'.
+#
+# 'e' can only be followed by 'i'.
+#
+# 'i' can only be followed by 'a', 'e', 'o', and 'u'.
+#
+# 'o' can only be followed by 'a' and 'u'.
+#
+# 'u' can only be followed by 'o' and 'e'.
+#
+# For example, if the given integer N = 2 then script should print the following
+# strings:
+#
+# ae
+# ai
+# ei
+# ia
+# io
+# iu
+# ie
+# oa
+# ou
+# uo
+# ue
+
+import sys
+
+def show_vowels(n, string):
+ if len(string) == n:
+ print(string)
+ elif string == "":
+ for vowel in ['a', 'e', 'i', 'o', 'u']:
+ show_vowels(n, string+vowel)
+ elif string[-1] == 'a':
+ for vowel in ['e', 'i']:
+ show_vowels(n, string+vowel)
+ elif string[-1] == 'e':
+ for vowel in ['i']:
+ show_vowels(n, string+vowel)
+ elif string[-1] == 'i':
+ for vowel in ['a', 'e', 'o', 'u']:
+ show_vowels(n, string+vowel)
+ elif string[-1] == 'o':
+ for vowel in ['a', 'u']:
+ show_vowels(n, string+vowel)
+ elif string[-1] == 'u':
+ for vowel in ['e', 'o']:
+ show_vowels(n, string+vowel)
+ else:
+ print("expected vowel, got "+string)
+
+n = int(sys.argv[1])
+show_vowels(n, "")