-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgpt4_solution.py
More file actions
61 lines (55 loc) · 1.86 KB
/
Copy pathgpt4_solution.py
File metadata and controls
61 lines (55 loc) · 1.86 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
53
54
55
56
57
58
59
60
61
import json
import time
# START - CODE GENERATED BY gpt4
def solution():
def generate_polygonal_numbers(s, start, end):
n = 1
numbers = []
while True:
if s == 3:
num = n * (n + 1) // 2
elif s == 4:
num = n * n
elif s == 5:
num = n * (3 * n - 1) // 2
elif s == 6:
num = n * (2 * n - 1)
elif s == 7:
num = n * (5 * n - 3) // 2
elif s == 8:
num = n * (3 * n - 2)
if num >= end:
break
if num >= start:
numbers.append(num)
n += 1
return numbers
def find_cyclic_set(sets, path, used):
if len(path) == 6:
if path[-1] % 100 == path[0] // 100:
return path
return None
for i in range(6):
if not used[i]:
for number in sets[i]:
if path[-1] % 100 == number // 100:
used[i] = True
result = find_cyclic_set(sets, path + [number], used)
if result:
return result
used[i] = False
return None
polygonal_sets = [generate_polygonal_numbers(s, 1000, 10000) for s in range(3, 9)]
for i in range(6):
for number in polygonal_sets[i]:
used = [False] * 6
used[i] = True
result = find_cyclic_set(polygonal_sets, [number], used)
if result:
return sum(result)
# 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}))