use std::cmp; static MONTH_DAYS: &'static [i32] = &[ 0, // dummy 31, // Jan 28, // Feb 31, // Mar 30, // Apr 31, // May 30, // Jun 31, // Jul 31, // Aug 30, // Sep 31, // Oct 30, // Nov 31, // Dec ]; fn solve() { // 1..9 // - 1 : 01 - 10, (01, 10) // - 2 : 02 - 20, (12, 11, 20) // - 3 : 03 - 30, (03, 12, 21, 30) // - 4 : 04 - max (04, 13, 22), NG: 31 // - 5 : 05 - max (05, 14, 23), NG: 32, 41 // ... // - 9 : 09 - max (09, 18, 27), NG: 36, 45, ... // 10..12 // - 10 : 10 - max (19, 28), NG : 37, 46, ... // - 11 : 11 - max (29), NG : 38, 47, ... // - 12 : 12 - max (), NG : 39, 48, ... let mut count = 0; for month in 1..=12 { let start = if month < 10 { month } else { (month - 9) * 10 + 9 }; let stop = cmp::min(month * 10, MONTH_DAYS[month as usize]); if start > stop { break; } for offset in 0..4 { let happy_day = start + offset * 9; if happy_day > stop { break; } count += 1; } } println!("{}", count); } fn main() { solve(); }