diff options
| author | Lubos Kolouch <lubos@kolouch.net> | 2022-03-05 14:23:57 +0100 |
|---|---|---|
| committer | Lubos Kolouch <lubos@kolouch.net> | 2022-03-05 14:23:57 +0100 |
| commit | 3df30438e3156f725518a293a27aa097eb0c5256 (patch) | |
| tree | ce4791a56d1778b9c9652b5d52e08e88d05d7dbc /challenge-154 | |
| parent | 3469330d9cac6c82b9930bc450d897957e8e0e88 (diff) | |
| download | perlweeklychallenge-club-3df30438e3156f725518a293a27aa097eb0c5256.tar.gz perlweeklychallenge-club-3df30438e3156f725518a293a27aa097eb0c5256.tar.bz2 perlweeklychallenge-club-3df30438e3156f725518a293a27aa097eb0c5256.zip | |
feat(challenge-154/lubos-kolouch/python/ch-1.py,-ch-2.py): Challenge 154 LK Task 1 2 Python
Diffstat (limited to 'challenge-154')
| -rw-r--r-- | challenge-154/lubos-kolouch/python/ch-1.py | 46 | ||||
| -rw-r--r-- | challenge-154/lubos-kolouch/python/ch-2.py | 55 |
2 files changed, 101 insertions, 0 deletions
diff --git a/challenge-154/lubos-kolouch/python/ch-1.py b/challenge-154/lubos-kolouch/python/ch-1.py new file mode 100644 index 0000000000..9ab2fca254 --- /dev/null +++ b/challenge-154/lubos-kolouch/python/ch-1.py @@ -0,0 +1,46 @@ +""" Challenge 154 Task 1 LK """ +from itertools import permutations + + +def find_missing(what: list): + """Find the missing permutations""" + + all_perms = permutations("PERL") + + output = [] + + for perm in all_perms: + look_str = "".join(perm) + if look_str not in what: + output.append(look_str) + + return output + + +assert find_missing( + [ + "PELR", + "PREL", + "PERL", + "PRLE", + "PLER", + "PLRE", + "EPRL", + "EPLR", + "ERPL", + "ERLP", + "ELPR", + "ELRP", + "RPEL", + "RPLE", + "REPL", + "RELP", + "RLPE", + "RLEP", + "LPER", + "LPRE", + "LEPR", + "LRPE", + "LREP", + ] +) == ["LERP"] diff --git a/challenge-154/lubos-kolouch/python/ch-2.py b/challenge-154/lubos-kolouch/python/ch-2.py new file mode 100644 index 0000000000..a9a5f65f57 --- /dev/null +++ b/challenge-154/lubos-kolouch/python/ch-2.py @@ -0,0 +1,55 @@ +""" Challenge 154 Task 2 LK """ +from sympy import isprime + + +class PadovanPrimes: + def __init__(self): + + self.nums_cache = [1, 1, 1] + self.seen_nums = {} + + def gen_next_num(self): + """Calculate the next Padovan num""" + self.nums_cache.append(self.nums_cache[-2] + self.nums_cache[-3]) + + def get_n_unique(self, what: int): + """Get the n unique numbers""" + + counter = 0 + output = [] + + while counter < what: + self.gen_next_num() + + if not isprime(self.nums_cache[-1]): + continue + + if self.seen_nums.get(self.nums_cache[-1], -1) != -1: + continue + + output.append(self.nums_cache[-1]) + counter += 1 + self.seen_nums[self.nums_cache[-1]] = 1 + + return output + + +def main(): + """Do the main thing""" + padovan = PadovanPrimes() + assert padovan.get_n_unique(10) == [ + 2, + 3, + 5, + 7, + 37, + 151, + 3329, + 23833, + 13091204281, + 3093215881333057, + ] + + +if __name__ == "__main__": + main() |
