Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def findPrimesTo(n):
- primes = []
- for potentialPrime in range(2, n + 1, 1):
- isPrime = True
- for prime in primes:
- if potentialPrime % prime == 0:
- isPrime = False
- break
- for divisor in range(2, int(potentialPrime ** 0.5) + 1, 1):
- if potentialPrime % divisor == 0:
- isPrime = False
- break
- if isPrime:
- primes.append(potentialPrime)
- return primes
- def PE43():
- from itertools import permutations
- primes = findPrimesTo(17)
- possibles = []
- gooduns = []
- dog = permutations('0123456789', 10)
- for cat in dog:
- collar = ''
- for mouse in cat:
- collar += mouse
- possibles.append(int(collar))
- for x in possibles:
- rope = str(x)
- good = True
- for y in range(1, 8, 1):
- if int(rope[y:y + 3]) % primes[y - 1] != 0:
- good = False
- break
- if good:
- gooduns.append(x)
- return sum(gooduns)
- PE43()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement