-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgpt4_solution.py
More file actions
25 lines (20 loc) · 952 Bytes
/
Copy pathgpt4_solution.py
File metadata and controls
25 lines (20 loc) · 952 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
import json
import time
# START - CODE GENERATED BY gpt4
def solution():
# Read the triangle from the file
with open('p067_triangle.txt', 'r') as file:
triangle = [[int(num) for num in line.split()] for line in file]
# Start from the second to last row and move upwards
for row in range(len(triangle) - 2, -1, -1):
for col in range(len(triangle[row])):
# Update the current element to be the sum of itself and the maximum of the two adjacent numbers below
triangle[row][col] += max(triangle[row + 1][col], triangle[row + 1][col + 1])
# The top element now contains the maximum total
return triangle[0][0]
# 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}))