-
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) · 920 Bytes
/
Copy pathgpt4_solution.py
File metadata and controls
32 lines (26 loc) · 920 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():
# Generate the sequence for e's continued fraction
e_sequence = [2]
k = 1
while len(e_sequence) < 100:
e_sequence.extend([1, 2 * k, 1])
k += 1
# Initialize the first two convergents
num1, num2 = 1, e_sequence[0]
den1, den2 = 0, 1
# Calculate the 100th convergent
for i in range(1, 100):
a = e_sequence[i]
num1, num2 = num2, a * num2 + num1
den1, den2 = den2, a * den2 + den1
# Sum the digits of the numerator of the 100th convergent
return sum(int(digit) for digit in str(num2))
# 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}))