From ed27192f0d21373e9600d6cebfb821037bd6a61d Mon Sep 17 00:00:00 2001 From: Coin de Gamma Date: Fri, 24 Mar 2023 16:42:03 +0000 Subject: [PATCH] 019 ok --- 019/Cargo.toml | 10 ++++++++++ 019/src/main.rs | 25 +++++++++++++++++++++++++ 2 files changed, 35 insertions(+) create mode 100644 019/Cargo.toml create mode 100644 019/src/main.rs diff --git a/019/Cargo.toml b/019/Cargo.toml new file mode 100644 index 0000000..c553330 --- /dev/null +++ b/019/Cargo.toml @@ -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" + diff --git a/019/src/main.rs b/019/src/main.rs new file mode 100644 index 0000000..c32d4e6 --- /dev/null +++ b/019/src/main.rs @@ -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); +}