-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgpt3_solution.py
More file actions
37 lines (32 loc) · 953 Bytes
/
Copy pathgpt3_solution.py
File metadata and controls
37 lines (32 loc) · 953 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
import json
import time
# START - CODE GENERATED BY gpt3
from itertools import permutations
import math
def is_prime(n):
if n <= 1:
return False
elif n <= 3:
return True
elif 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 solution():
for n in range(9, 0, -1):
digits = [str(i) for i in range(1, n+1)]
pandigitals = list(permutations(digits))
for pandigital in pandigitals[::-1]:
num = int(''.join(pandigital))
if is_prime(num):
return num
# 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}))