From c25b761e932a2999e723d436139387d08aeb70d5 Mon Sep 17 00:00:00 2001 From: Jim Infield Date: Mon, 2 Aug 2021 21:25:03 -0500 Subject: [PATCH] initial codewars submission --- src/main.rs | 58 ++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 57 insertions(+), 1 deletion(-) diff --git a/src/main.rs b/src/main.rs index e7a11a9..0e27b9d 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,3 +1,59 @@ fn main() { - println!("Hello, world!"); + println!(); + + let mut str = ('a'..='z').collect::(); + let bad = ('n'..='z').collect::(); + let rng: Vec<_> = ('n'..='z').collect(); + let err: &[_] = &&rng; + let sls = ""; + let st2 = "kkkwwwaaaaaaaaaaaaaabbbbbbbbbbbbbbbbbbmmmmmmmmmmmmmmmmmmmxyz"; + + println!("{:?}\t{:?}\t{:?}\t{:?}", + func(&str), + &str.trim_matches(err), + str.len(), + sls + ); + + println!("\n{:?}\n{:?}\t{:?}:{:?}", + st2, + st2.chars().filter(|&c| err.contains(&c)).collect::(), + st2.chars().filter(|&c| "nopqrstuvwxyz".contains(c)).count(), + st2.len() + ); + + println!("\n{:?}\n{:?}\t{:?}:{:?}", + st2, + st2.chars().filter(|&c| c > 'm').collect::(), + st2.chars().filter(|&c| c > 'm').count(), + st2.len() + ); + + println!("\n{:?}\t{:?}", + str, + str.chars().filter(|&c| err.contains(&c)).collect::(), + ); + + println!(); +} + +fn func(s: &str) -> String { + s.into() +} +fn printer_error(s: &str) -> String { + format!("{}/{}", + s.chars().filter(|&c| "nopqrstuvwxyz".contains(c)).count(), + s.len() + ) +} + +#[cfg(test)] +mod tests { + use super::*; + #[test] + fn should_pass_all_the_tests_provided() { + assert_eq!(&printer_error("aaaaaaaaaaaaaaaabbbbbbbbbbbbbbbbbbmmmmmmmmmmmmmmmmmmmxyz"), "3/56"); + assert_eq!(&printer_error("kkkwwwaaaaaaaaaaaaaabbbbbbbbbbbbbbbbbbmmmmmmmmmmmmmmmmmmmxyz"), "6/60"); + assert_eq!(&printer_error("kkkwwwaaaaaaaaaaaaaabbbbbbbbbbbbbbbbbbmmmmmmmmmmmmmmmmmmmxyzuuuuu"), "11/65"); + } }