-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgpt3_solution.py
More file actions
40 lines (37 loc) · 1.34 KB
/
Copy pathgpt3_solution.py
File metadata and controls
40 lines (37 loc) · 1.34 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
import json
import time
# START - CODE GENERATED BY gpt3
def solution():
# Define a dictionary to store the number of letters in each word
num_dict = {
1: 3, 2: 3, 3: 5, 4: 4, 5: 4, 6: 3, 7: 5, 8: 5, 9: 4, 10: 3,
11: 6, 12: 6, 13: 8, 14: 8, 15: 7, 16: 7, 17: 9, 18: 8, 19: 8,
20: 6, 30: 6, 40: 5, 50: 5, 60: 5, 70: 7, 80: 6, 90: 6
}
# Define a function to count the number of letters in a given number
def count_letters(n):
if n == 1000:
return 11
elif n >= 100:
if n % 100 == 0:
return num_dict[n // 100] + 7
else:
return num_dict[n // 100] + 10 + count_letters(n % 100)
elif n >= 20:
if n % 10 == 0:
return num_dict[n]
else:
return num_dict[n // 10 * 10] + num_dict[n % 10]
else:
return num_dict[n]
# Sum up the number of letters in all numbers from 1 to 1000
total_letters = 0
for i in range(1, 1001):
total_letters += count_letters(i)
return total_letters
# END - CODE GENERATED BY gpt3
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}))