Taddeus Kroes 13 жил өмнө
parent
commit
aa991260ff
2 өөрчлөгдсөн 27 нэмэгдсэн , 0 устгасан
  1. 24 0
      problem49.py
  2. 3 0
      utils.py

+ 24 - 0
problem49.py

@@ -0,0 +1,24 @@
+#!/usr/bin/env python
+from itertools import permutations, combinations
+from utils import primes_until, digits, add
+from sys import exit
+
+def concat(digits):
+    return int(reduce(add, digits))
+
+def suited(n):
+    return n > 999 and n not in (1487, 4817, 8147) and n in primes
+
+primes = [p for p in primes_until(10000) if p > 999]
+
+for p in primes:
+    perm = map(concat, permutations(str(p)))
+
+    for a, b, c in set(combinations(perm, 3)):
+        if a >= b or a >= c or b >= c \
+                or b - a != c - b or b - a < 1000 \
+                or not all(map(suited, (a, b, c))):
+            continue
+
+        print '%d%d%d' % (a, b, c)
+        exit()

+ 3 - 0
utils.py

@@ -1,3 +1,6 @@
+def add(a, b):
+    return a + b
+
 def digits(n):
     return [n] if n < 10 else digits(n / 10) + [n % 10]