-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgpt4_solution.py
More file actions
36 lines (27 loc) · 925 Bytes
/
Copy pathgpt4_solution.py
File metadata and controls
36 lines (27 loc) · 925 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
import json
import time
# START - CODE GENERATED BY gpt4
def solution():
def triangle_number(n):
return n * (n + 1) // 2
def pentagonal_number(n):
return n * (3 * n - 1) // 2
def hexagonal_number(n):
return n * (2 * n - 1)
# Start searching from the next number after the known solution
n_t, n_p, n_h = 286, 166, 144
while True:
t = triangle_number(n_t)
while pentagonal_number(n_p) < t:
n_p += 1
while hexagonal_number(n_h) < t:
n_h += 1
if t == pentagonal_number(n_p) == hexagonal_number(n_h):
return t
n_t += 1
# 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}))