scramble prime challenge
|
02-14-2020, 04:02 PM
(This post was last modified: 02-18-2020 09:24 PM by Albert Chan.)
Post: #9
|
|||
|
|||
RE: scramble prime challenge
I tried building the primes first, but it turns out very slow.
Instead, I loop over permutations, but only the digits sorted cases. This reduces the permutations to manageable size. Code: digits permutations to check Another benefit is there is no big list to handle, with space complexity = O(digits) Code: from gmpy2 import is_prime, mpz >>> for d in xrange(2,21): print d, list(scramble_primes(d)) ... 2 [11, 13, 17, 37, 79] 3 [113, 199, 337] 4 [] 5 [] 6 [] 7 [] 8 [] 9 [] 10 [] 11 [] 12 [] 13 [] 14 [] 15 [] 16 [] 17 [] 18 [] 19 [1111111111111111111L] # see http://oeis.org/A004022 20 [] Above take 0.3 seconds on my laptop |
|||
« Next Oldest | Next Newest »
|
User(s) browsing this thread: 2 Guest(s)