day2's challenge

main
Ray Slakinski 2020-12-02 09:34:08 -05:00
parent d8dbdca446
commit 4a0f4584dd
2 changed files with 1025 additions and 1 deletions

1000
2020/day_2/input1 100644

File diff suppressed because it is too large Load Diff

View File

@ -1,3 +1,27 @@
fn main() {
println!("Hello, world!");
let mut passline: Vec<String> = Vec::new();
let contents = std::fs::read_to_string("input1").unwrap();
for s in contents.lines() {
passline.push(s.parse::<String>().unwrap());
}
let mut valid_passwords = 0;
for line in passline.iter() {
let psplit: Vec<&str> = line.split(" ").collect();
let r: Vec<&str> = psplit[0].split("-").collect();
let min: usize = r[0].parse().unwrap();
let max: usize = r[1].parse().unwrap();
let key: u8 = psplit[1].chars().next().unwrap() as u8;
let pass = psplit[2];
// let c = pass.matches(key).count();
// if c >= min && c <= max {
// valid_passwrods += 1;
// }
if (pass.as_bytes()[min - 1] == key && pass.as_bytes()[max - 1] != key)
|| (pass.as_bytes()[min - 1] != key && pass.as_bytes()[max - 1] == key)
{
valid_passwords += 1;
}
// print!("{} {} {} {}\n", min, max, key, pass);
}
print!("Valid Passwords Found: {}\n", valid_passwords);
}