aboutsummaryrefslogtreecommitdiff
path: root/challenge-154/bruce-gray/python
diff options
context:
space:
mode:
Diffstat (limited to 'challenge-154/bruce-gray/python')
-rw-r--r--challenge-154/bruce-gray/python/ch-1.py9
-rw-r--r--challenge-154/bruce-gray/python/ch-2.py25
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()))))