-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgpt4_solution.py
More file actions
51 lines (43 loc) · 1.66 KB
/
Copy pathgpt4_solution.py
File metadata and controls
51 lines (43 loc) · 1.66 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
41
42
43
44
45
46
47
48
49
50
51
import json
import time
# START - CODE GENERATED BY gpt4
def solution():
# Days in each month, index 0 is January, index 11 is December
days_in_month = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
def is_leap_year(year):
if year % 4 == 0:
if year % 100 == 0:
if year % 400 == 0:
return True
else:
return False
else:
return True
else:
return False
# Start on 1 Jan 1900, which is a Monday
current_day_of_week = 0 # Monday
# Calculate the day of the week for 1 Jan 1901
for year in range(1900, 1901):
for month in range(12):
if month == 1 and is_leap_year(year):
current_day_of_week = (current_day_of_week + 29) % 7
else:
current_day_of_week = (current_day_of_week + days_in_month[month]) % 7
# Count Sundays on the first of the month from 1901 to 2000
sunday_count = 0
for year in range(1901, 2001):
for month in range(12):
if current_day_of_week == 6: # Sunday
sunday_count += 1
if month == 1 and is_leap_year(year):
current_day_of_week = (current_day_of_week + 29) % 7
else:
current_day_of_week = (current_day_of_week + days_in_month[month]) % 7
return sunday_count
# 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}))