diff options
| author | Util <bruce.gray@acm.org> | 2022-03-06 00:16:38 -0600 |
|---|---|---|
| committer | Util <bruce.gray@acm.org> | 2022-03-06 00:16:38 -0600 |
| commit | b68edfed700bb9ea073f1d7b514dee22c3bf3b28 (patch) | |
| tree | 7e86d694294588a321a4a67154bebf7a715d9d68 /challenge-154/bruce-gray/python | |
| parent | b45785bb469b127b9ab48e53b1efe2d435cfc193 (diff) | |
| download | perlweeklychallenge-club-b68edfed700bb9ea073f1d7b514dee22c3bf3b28.tar.gz perlweeklychallenge-club-b68edfed700bb9ea073f1d7b514dee22c3bf3b28.tar.bz2 perlweeklychallenge-club-b68edfed700bb9ea073f1d7b514dee22c3bf3b28.zip | |
Add TWC 154 solutions by Bruce Gray : Raku, Perl, and Python.
Diffstat (limited to 'challenge-154/bruce-gray/python')
| -rw-r--r-- | challenge-154/bruce-gray/python/ch-1.py | 9 | ||||
| -rw-r--r-- | challenge-154/bruce-gray/python/ch-2.py | 25 |
2 files changed, 34 insertions, 0 deletions
diff --git a/challenge-154/bruce-gray/python/ch-1.py b/challenge-154/bruce-gray/python/ch-1.py new file mode 100644 index 0000000000..141148a05b --- /dev/null +++ b/challenge-154/bruce-gray/python/ch-1.py @@ -0,0 +1,9 @@ +from itertools import permutations + +input_words = "PELR PREL PERL PRLE PLER PLRE EPRL EPLR ERPL ERLP ELPR ELRP RPEL RPLE REPL RELP RLPE RLEP LPER LPRE LEPR LRPE LREP".split() +input_set = set(input_words) + +for i in permutations(list(input_words[0])): + s = "".join(i) + if s not in input_set: + print(s) diff --git a/challenge-154/bruce-gray/python/ch-2.py b/challenge-154/bruce-gray/python/ch-2.py new file mode 100644 index 0000000000..aef20b2f69 --- /dev/null +++ b/challenge-154/bruce-gray/python/ch-2.py @@ -0,0 +1,25 @@ +from sympy import isprime +from itertools import islice + + +def Padovan(): + p = [1, 1, 1] + + while True: + p.append(p[-2] + p[-3]) + yield p.pop(0) + + +def squish(a): + last = None + for i in a: + if i != last: + yield i + last = i + + +def head(n, iterable): + return list(islice(iterable, n)) + + +print(head(10, squish(filter(isprime, Padovan())))) |
