Widespread Augmented Reality

Widespread Augmented Reality
Click on the image to get the Android Augmented Reality Heads up Display

Thursday, March 30, 2023

Python Brute Force Solution to Euler Project Problem 60

My cumbersome solution to https://projecteuler.net/problem=60 but I'll take it. I cheated by setting the loop limits to 10000.

import math
from math import sqrt
def isPrime(n):
prime_flag = 0
if(n > 1):
for i in range(2, int(sqrt(n)) + 1):
if (n % i == 0):
prime_flag = 1
break
if (prime_flag == 0):
return True
else:
return False
else:
return False
# main sequence
concatprime = False
start = 2
for a in range(start, 10000):
if isPrime(a) and concatprime == False:
for b in range(a+1, 10000):
if isPrime(b):
ab = str(a)+str(b)
ba = str(b)+str(a)
if isPrime(int(ab)) and isPrime(int(ba)):
#print(str(a)+","+str(b))
for c in range(b+1, 10000):
if isPrime(c):
ac = str(a)+str(c)
ca = str(c)+str(a)
bc = str(b)+str(c)
cb = str(c)+str(b)
if isPrime(int(ac)) and isPrime(int(ca)) and isPrime(int(bc)) and isPrime(int(cb)):
#print(str(a)+","+str(b)+","+str(c))
for d in range(c+1, 10000):
if isPrime(d):
da = str(d)+str(a)
ad = str(a)+str(d)
db = str(d)+str(b)
bd = str(b)+str(d)
dc = str(d)+str(c)
cd = str(c)+str(d)
if isPrime(int(da)) and isPrime(int(ad)) and isPrime(int(db)) and isPrime(int(bd)) and isPrime(int(dc)) and isPrime(int(cd)):
#print(str(a)+","+str(b)+","+str(c)+","+str(d))
for e in range(d+1, 10000):
if isPrime(e):
ea = str(e)+str(a)
ae = str(a)+str(e)
eb = str(e)+str(b)
be = str(b)+str(e)
ec = str(e)+str(c)
ce = str(c)+str(e)
ed = str(e)+str(d)
de = str(d)+str(e)
if isPrime(int(ea)) and isPrime(int(ae)) and isPrime(int(eb)) and isPrime(int(be)) and isPrime(int(ec)) and isPrime(int(ce)) and isPrime(int(ed)) and isPrime(int(de)):
print(str(a)+","+str(b)+","+str(c)+","+str(d)+","+str(e))
print(a+b+c+d+e)
concatprime = True
#start = 10000
break

No comments:

Post a Comment