import time as t
start = t.perf_counter()
def leap_year(year):
if year % 4:
return 0
else:
if year % 100:
return 1
elif year % 400:
return 0
else:
return 1
res, sundays = 1, 0
dates, leap_years = [], []
for i in range(1901, 2001):
is_leap = leap_year(i)
month_day =
count_month = 1
for month in month_day:
count_month += 1
res += month
if not ((res + 1) % 7):
sundays += 1
if count_month < 13:
date = "%s.%s" % (i, count_month)
dates.append(date)
else:
date = "%s.%s" % (i + 1, 1)
dates.append(date)
for i in dates:
print(i)
print(sundays)
print("It costs %f s" % (t.perf_counter() - start)) import time as t
start = t.perf_counter()
def leap_year(year):
if year % 4:
return 0
else:
if year % 100:
return 1
elif year % 400:
return 0
else:
return 1
res, sundays = 1, 0
dates, leap_years = [], []
for i in range(1901, 2001):
is_leap = leap_year(i)
month_day =
count_month = 1
for month in month_day:
count_month += 1
res += month
if not ((res + 1) % 7):
sundays += 1
if count_month < 13:
date = "%s.%s" % (i, count_month)
dates.append(date)
else:
date = "%s.%s" % (i + 1, 1)
dates.append(date)
for i in dates:
print(i)
print(sundays)
print("It costs %f s" % (t.perf_counter() - start)) use chrono::prelude::*;
pub fn run() -> Result<(), Box<dyn std::error::Error>> {
let mut count = 0;
let mut day = Utc.ymd(1901, 1, 1);
while day <= Utc.ymd(2000, 12, 31) {
if day.weekday() == Weekday::Sun && day.day() == 1 {count += 1;}
day += chrono::Duration::days(1)
}
println!("{count}");
Ok(())
}
171
页:
1
[2]