diff options
Diffstat (limited to 'challenge-154/bruce-gray/python/ch-2.py')
| -rw-r--r-- | challenge-154/bruce-gray/python/ch-2.py | 25 |
1 files changed, 25 insertions, 0 deletions
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())))) |
