-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgpt4_solution.py
More file actions
35 lines (27 loc) · 981 Bytes
/
Copy pathgpt4_solution.py
File metadata and controls
35 lines (27 loc) · 981 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
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
# Precompute factorials of digits 0-9
factorials = [factorial(i) for i in range(10)]
# Upper bound: 7 * 9! = 2540160, because 8 * 9! is still a 7-digit number
upper_bound = 7 * factorials[9]
curious_sum = 0
for number in range(10, upper_bound):
digit_factorial_sum = sum(factorials[int(digit)] for digit in str(number))
if digit_factorial_sum == number:
curious_sum += number
return curious_sum
# 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}))