-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgpt4_solution.py
More file actions
36 lines (31 loc) · 1.17 KB
/
Copy pathgpt4_solution.py
File metadata and controls
36 lines (31 loc) · 1.17 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
import json
import time
# START - CODE GENERATED BY gpt4
def solution():
# Initialize variables
product = 1
current_length = 0
target_positions = [1, 10, 100, 1000, 10000, 100000, 1000000]
current_number = 1
target_index = 0
# Loop until we reach the last target position
while target_index < len(target_positions):
# Convert current number to string to iterate over its digits
current_str = str(current_number)
for digit in current_str:
current_length += 1
# Check if the current position is a target position
if current_length == target_positions[target_index]:
product *= int(digit)
target_index += 1
# Break if all target positions are found
if target_index >= len(target_positions):
break
current_number += 1
return product
# 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}))