problem49.py 649 B

123456789101112131415161718192021222324
  1. #!/usr/bin/env python
  2. from itertools import permutations, combinations
  3. from utils import primes_until, add
  4. from sys import exit
  5. def concat(digits):
  6. return int(reduce(add, digits))
  7. def suited(n):
  8. return n > 999 and n not in (1487, 4817, 8147) and n in primes
  9. primes = [p for p in primes_until(10000) if p > 999]
  10. for p in primes:
  11. perm = map(concat, permutations(str(p)))
  12. for a, b, c in set(combinations(perm, 3)):
  13. if a >= b or a >= c or b >= c \
  14. or b - a != c - b or b - a < 1000 \
  15. or not all(map(suited, (a, b, c))):
  16. continue
  17. print '%d%d%d' % (a, b, c)
  18. exit()