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