Skip to content

Instantly share code, notes, and snippets.

@dazfuller
Created January 13, 2015 14:09
Show Gist options
  • Save dazfuller/7e6b423de972ab122200 to your computer and use it in GitHub Desktop.
Save dazfuller/7e6b423de972ab122200 to your computer and use it in GitHub Desktop.
Project Euler - Problem 41
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