1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
|
#!/usr/bin/env python
""" PerlWeeklyChallenge 053"""
from itertools import permutations
class VowelString:
""" Produce all valid permutations"""
def __init__(self):
self.permutation = ''
def check_valid(self):
""" Check if given permutation is valid"""
ok_rules = ['ae', 'ai', 'ei', 'ia', 'ie',
'io', 'iu', 'oa', 'ou', 'uo', 'ue']
for item_count, item in enumerate(self.permutation[:-1]):
if item + self.permutation[item_count+1] not in ok_rules:
return 0
return 1
def get_permutations(self, count: int):
""" process all possible permutations"""
wovels = ['a', 'e', 'i', 'o', 'u']
result = []
for perm in permutations(wovels, count):
self.permutation = perm
if self.check_valid():
result.append(perm)
return result
class TestVowelString:
"""Test for the VowelString method"""
def __init__(self):
self.vow = VowelString()
def do_tests(self):
"""Run the tests"""
assert len(self.vow.get_permutations(1)) == 0
assert len(self.vow.get_permutations(2)) == 11
def main():
"""Main method"""
vowcomb = VowelString()
print(vowcomb.get_permutations(2))
vowtester = TestVowelString()
vowtester.do_tests()
if __name__ == "__main__":
main()
|