-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgpt4_solution.py
More file actions
32 lines (26 loc) · 897 Bytes
/
Copy pathgpt4_solution.py
File metadata and controls
32 lines (26 loc) · 897 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
import json
import time
# START - CODE GENERATED BY gpt4
def solution():
def factorial(n):
if n == 0 or n == 1:
return 1
result = 1
for i in range(2, n + 1):
result *= i
return result
digits = list(range(10))
target_permutation_index = 1000000 - 1 # zero-based index
permutation = []
for i in range(len(digits) - 1, -1, -1):
fact = factorial(i)
index = target_permutation_index // fact
permutation.append(digits.pop(index))
target_permutation_index %= fact
return int(''.join(map(str, permutation)))
# 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}))