aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--challenge-254/steven-wilson/python/ch-01.py24
-rw-r--r--challenge-254/steven-wilson/python/ch-02.py40
2 files changed, 64 insertions, 0 deletions
diff --git a/challenge-254/steven-wilson/python/ch-01.py b/challenge-254/steven-wilson/python/ch-01.py
new file mode 100644
index 0000000000..6c51d189e2
--- /dev/null
+++ b/challenge-254/steven-wilson/python/ch-01.py
@@ -0,0 +1,24 @@
+#!/usr/bin/env python3
+
+import math
+
+
+def is_power_three(number):
+ ''' Given a positive integer. Returns true if the given integer is a power
+ of three otherwise returns false.
+
+ >>> is_power_three(27)
+ True
+ >>> is_power_three(0)
+ True
+ >>> is_power_three(6)
+ False
+ '''
+ cr = round(math.pow(number, 1/3), 6)
+ return ((cr - int(cr)) == 0)
+
+
+if __name__ == "__main__":
+ import doctest
+
+ doctest.testmod()
diff --git a/challenge-254/steven-wilson/python/ch-02.py b/challenge-254/steven-wilson/python/ch-02.py
new file mode 100644
index 0000000000..3d2a7d6821
--- /dev/null
+++ b/challenge-254/steven-wilson/python/ch-02.py
@@ -0,0 +1,40 @@
+#!/usr/bin/env python3
+
+
+VOWELS = ['a', 'e', 'i', 'o', 'u']
+
+
+def reverse_vowels(string):
+ ''' Given a string reverse all the vowels (a, e, i, o, u) and return
+ resulting string.
+
+ >>> reverse_vowels('Raku')
+ 'Ruka'
+ >>> reverse_vowels('Perl')
+ 'Perl'
+ >>> reverse_vowels('Julia')
+ 'Jaliu'
+ >>> reverse_vowels('Uiua')
+ 'Auiu'
+ '''
+ string = string.lower()
+ indexes = []
+ cs = []
+ for index, c in enumerate(string):
+ if c in VOWELS:
+ indexes.append(index)
+ cs.append(c)
+
+ if len(indexes) < 2:
+ return string.title()
+ else:
+ characters = list(string)
+ for index in indexes:
+ characters[index] = cs.pop()
+ return ''.join(characters).title()
+
+
+if __name__ == "__main__":
+ import doctest
+
+ doctest.testmod()