playing with scan_fmt! omg <3
This commit is contained in:
parent
a0f7d2f25a
commit
8c36dff3d1
@ -7,3 +7,4 @@ edition = "2018"
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||
|
||||
[dependencies]
|
||||
scan_fmt = "0.2.5"
|
@ -1,3 +1,5 @@
|
||||
#[macro_use]
|
||||
extern crate scan_fmt;
|
||||
fn main() {
|
||||
let mut passline: Vec<String> = Vec::new();
|
||||
let contents = std::fs::read_to_string("input1").unwrap();
|
||||
@ -6,22 +8,13 @@ fn main() {
|
||||
}
|
||||
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)
|
||||
let (min, max, key, pass) =
|
||||
scan_fmt!(&line, "{}-{} {}: {}", usize, usize, char, String).unwrap();
|
||||
if (pass.as_bytes()[min - 1] == key as u8 && pass.as_bytes()[max - 1] != key as u8)
|
||||
|| (pass.as_bytes()[min - 1] != key as u8 && pass.as_bytes()[max - 1] == key as u8)
|
||||
{
|
||||
valid_passwords += 1;
|
||||
}
|
||||
// print!("{} {} {} {}\n", min, max, key, pass);
|
||||
}
|
||||
print!("Valid Passwords Found: {}\n", valid_passwords);
|
||||
}
|
||||
|
Reference in New Issue
Block a user