day2's challenge
This commit is contained in:
parent
d8dbdca446
commit
4a0f4584dd
1000
2020/day_2/input1
Normal file
1000
2020/day_2/input1
Normal file
File diff suppressed because it is too large
Load Diff
@ -1,3 +1,27 @@
|
|||||||
fn main() {
|
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);
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user