diff options
| author | Lubos Kolouch <lubos@kolouch.net> | 2020-03-26 13:29:38 +0100 |
|---|---|---|
| committer | Lubos Kolouch <lubos@kolouch.net> | 2020-03-26 13:29:38 +0100 |
| commit | 590ebd688e0d0209de35bc047e4850fcdd2e06b1 (patch) | |
| tree | 7d4ceecfc76a3822fc4976d9c533f0f94d97caa6 | |
| parent | 09f158a7187f117b5776bb8dc2bb22e6fa22f042 (diff) | |
| download | perlweeklychallenge-club-590ebd688e0d0209de35bc047e4850fcdd2e06b1.tar.gz perlweeklychallenge-club-590ebd688e0d0209de35bc047e4850fcdd2e06b1.tar.bz2 perlweeklychallenge-club-590ebd688e0d0209de35bc047e4850fcdd2e06b1.zip | |
Task 2 Python LK
| -rw-r--r-- | challenge-053/lubos-kolouch/python/ch-2.py | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/challenge-053/lubos-kolouch/python/ch-2.py b/challenge-053/lubos-kolouch/python/ch-2.py new file mode 100644 index 0000000000..ebde8125fc --- /dev/null +++ b/challenge-053/lubos-kolouch/python/ch-2.py @@ -0,0 +1,48 @@ +#!/usr/bin/env python + +from itertools import permutations + + +class VowelString: + + def check_valid(self, permutation): + + ok_rules = ['ae', 'ai', 'ei', 'ia', 'ie', + 'io', 'iu', 'oa', 'ou', 'uo', 'ue'] + + for x, item in enumerate(permutation[:-1]): + if item + permutation[x+1] not in ok_rules: + return 0 + + return 1 + + def get_permutations(self, count: int): + + wovels = ['a', 'e', 'i', 'o', 'u'] + + result = [] + + for perm in permutations(wovels, count): + if self.check_valid(perm): + result.append(perm) + + return(result) + + +class TestVowelString: + + def __init__(self): + self.vow = VowelString() + + def do_tests(self): + assert len(self.vow.get_permutations(1)) == 0 + assert len(self.vow.get_permutations(2)) == 11 + + +if __name__ == "__main__": + vowcomb = VowelString() + + print(vowcomb.get_permutations(2)) + + vowtester = TestVowelString() + vowtester.do_tests() |
