Small changes.
This commit is contained in:
61
2015/11/src/main.rs
Normal file
61
2015/11/src/main.rs
Normal file
@@ -0,0 +1,61 @@
|
||||
fn main() {
|
||||
println!("Hello, world!");
|
||||
}
|
||||
|
||||
fn validate(input: &str) -> bool {
|
||||
let count = input.chars()
|
||||
.collect::<Vec<char>>()
|
||||
.windows(3)
|
||||
.filter(|x| x[0] >= 'a' && x[2] <= 'z')
|
||||
.filter(|x| (x[1] as i8 - x[0] as i8) == 1 && (x[2] as i8 - x[1] as i8) == 1)
|
||||
.count();
|
||||
|
||||
if count <= 0 {
|
||||
return false;
|
||||
}
|
||||
|
||||
for c in &['i', 'o', 'l'] {
|
||||
if input.contains(*c) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
let count = input.chars()
|
||||
.collect::<Vec<char>>()
|
||||
.windows(2)
|
||||
.filter(|x| x[0] == x[1])
|
||||
.count();
|
||||
|
||||
if count < 2 {
|
||||
return false;
|
||||
}
|
||||
|
||||
true
|
||||
}
|
||||
|
||||
fn generate(input: &str) -> String {
|
||||
let mut password = String::from(input);
|
||||
|
||||
password
|
||||
}
|
||||
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::{validate, generate};
|
||||
|
||||
#[test]
|
||||
fn test_validate() {
|
||||
assert_eq!(false, validate("hijklmmn"));
|
||||
assert_eq!(false, validate("abbceffg"));
|
||||
assert_eq!(false, validate("abbcegjk"));
|
||||
assert_eq!(true, validate("abcdffaa"));
|
||||
assert_eq!(true, validate("ghjaabcc"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_generate() {
|
||||
assert_eq!(String::from("abcdffaa"), generate("abcdefgh"));
|
||||
assert_eq!(String::from("ghjaabcc"), generate("ghijklmn"));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user