Created
January 13, 2015 14:09
-
-
Save dazfuller/7e6b423de972ab122200 to your computer and use it in GitHub Desktop.
Project Euler - Problem 41
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import math, itertools, time | |
def is_prime(n): | |
if n < 2: | |
return False | |
limit = math.floor(math.sqrt(n)) | |
for i in range(2, limit+1): | |
if n%i == 0: | |
return False | |
return True | |
if __name__ == "__main__": | |
t0 = time.time() | |
s = '7654321' | |
for x in itertools.permutations(s): | |
n = int(''.join(x)) | |
if is_prime(n): | |
print(n) | |
break | |
t1 = time.time() | |
print("The solution took", t1-t0, "seconds") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment