Codewars: Rust workspace for solving the 'Printer Errors' kata
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

59 lines
1.6 KiB

fn main() {
println!();
let mut str = ('a'..='z').collect::<String>();
let bad = ('n'..='z').collect::<String>();
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::<String>(),
st2.chars().filter(|&c| "nopqrstuvwxyz".contains(c)).count(),
st2.len()
);
println!("\n{:?}\n{:?}\t{:?}:{:?}",
st2,
st2.chars().filter(|&c| c > 'm').collect::<String>(),
st2.chars().filter(|&c| c > 'm').count(),
st2.len()
);
println!("\n{:?}\t{:?}",
str,
str.chars().filter(|&c| err.contains(&c)).collect::<String>(),
);
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");
}
}