-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgpt4_solution.py
More file actions
43 lines (33 loc) · 1 KB
/
Copy pathgpt4_solution.py
File metadata and controls
43 lines (33 loc) · 1 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
import json
import time
# START - CODE GENERATED BY gpt4
def solution():
def is_pentagonal(x):
# Check if a number is pentagonal
n = (1 + (1 + 24 * x) ** 0.5) / 6
return n.is_integer()
def pentagonal(n):
# Generate the nth pentagonal number
return n * (3 * n - 1) // 2
pentagonals = []
n = 1
min_d = float('inf')
while True:
pn = pentagonal(n)
pentagonals.append(pn)
for pj in pentagonals[:-1]:
pk = pn
if is_pentagonal(pk - pj) and is_pentagonal(pk + pj):
d = pk - pj
if d < min_d:
min_d = d
if min_d != float('inf'):
break
n += 1
return min_d
# 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}))