Coin de Gamma
2 years ago
2 changed files with 35 additions and 0 deletions
@ -0,0 +1,10 @@
|
||||
[package] |
||||
name = "peulerproblem" |
||||
version = "0.1.0" |
||||
edition = "2021" |
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html |
||||
|
||||
[dependencies] |
||||
time = "0.3.20" |
||||
|
@ -0,0 +1,25 @@
|
||||
use time::Date; |
||||
use time::Month; |
||||
use time::Duration; |
||||
|
||||
fn main() { |
||||
let d_begin = Date::from_calendar_date(1901, Month::January, 1).unwrap(); |
||||
let d_end = Date::from_calendar_date(2000, Month::December, 31).unwrap(); |
||||
let dt = Duration::DAY; |
||||
let mut day_count = 0u32; |
||||
let mut sundays_count = 0u32; |
||||
let mut di = d_begin.clone(); |
||||
while di != d_end { |
||||
if di.weekday() == time::Weekday::Sunday { |
||||
if di.day() == 1 { |
||||
sundays_count += 1; |
||||
} |
||||
} |
||||
//println!("{}", di.weekday());
|
||||
di = di.checked_add(dt).unwrap(); |
||||
day_count += 1; |
||||
} |
||||
|
||||
println!("day_count: {}", day_count); |
||||
println!("sundays count: {}", sundays_count); |
||||
} |
Loading…
Reference in new issue