-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgpt4_solution.py
More file actions
52 lines (46 loc) · 1.9 KB
/
Copy pathgpt4_solution.py
File metadata and controls
52 lines (46 loc) · 1.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import json
import time
# START - CODE GENERATED BY gpt4
def is_prime(n):
if n <= 1:
return False
if n <= 3:
return True
if n % 2 == 0 or n % 3 == 0:
return False
i = 5
while i * i <= n:
if n % i == 0 or n % (i + 2) == 0:
return False
i += 6
return True
def concatenate_and_check_prime(p1, p2):
return is_prime(int(str(p1) + str(p2))) and is_prime(int(str(p2) + str(p1)))
def find_lowest_sum_of_five_primes():
primes = [2]
n = 3
while True:
if is_prime(n):
primes.append(n)
for a in range(len(primes)):
if not concatenate_and_check_prime(primes[a], n):
continue
for b in range(a):
if not concatenate_and_check_prime(primes[b], n) or not concatenate_and_check_prime(primes[b], primes[a]):
continue
for c in range(b):
if not concatenate_and_check_prime(primes[c], n) or not concatenate_and_check_prime(primes[c], primes[a]) or not concatenate_and_check_prime(primes[c], primes[b]):
continue
for d in range(c):
if (concatenate_and_check_prime(primes[d], n) and concatenate_and_check_prime(primes[d], primes[a]) and
concatenate_and_check_prime(primes[d], primes[b]) and concatenate_and_check_prime(primes[d], primes[c])):
return primes[d] + primes[c] + primes[b] + primes[a] + n
n += 2
def solution():
return find_lowest_sum_of_five_primes()
# END - CODE GENERATED BY gpt4
cpu_s, wall_s = time.process_time(), time.time()
result = solution()
cpu_e, wall_e = time.process_time(), time.time()
cpu_time, wall_time = cpu_e - cpu_s, wall_e - wall_s
print(json.dumps({"solution": result, "cpu": cpu_time, "wall": wall_time}))