-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgpt3_solution.py
More file actions
41 lines (36 loc) · 960 Bytes
/
Copy pathgpt3_solution.py
File metadata and controls
41 lines (36 loc) · 960 Bytes
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
import json
import time
# START - CODE GENERATED BY gpt3
def is_prime(n):
if n < 2:
return False
for i in range(2, int(n**0.5)+1):
if n % i == 0:
return False
return True
def is_truncatable_prime(n):
if not is_prime(n):
return False
str_n = str(n)
for i in range(1, len(str_n)):
if not is_prime(int(str_n[i:])):
return False
if not is_prime(int(str_n[:i])):
return False
return True
def solution():
count = 0
total = 0
n = 11
while count < 11:
if is_truncatable_prime(n):
count += 1
total += n
n += 2
return total
# END - CODE GENERATED BY gpt3
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}))