Small changes.

This commit is contained in:
2016-12-23 19:52:02 +01:00
parent 5f8df692b6
commit df49cc1866
9 changed files with 338 additions and 2 deletions

61
2015/11/src/main.rs Normal file
View 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"));
}
}