diff --git a/.gitignore b/.gitignore index 9f370ae..33995ea 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,17 @@ main.pdb -main.exe \ No newline at end of file +main.exe + + +# Generated by Cargo +# will have compiled files and executables +debug/ +target/ + +# Remove Cargo.lock from gitignore if creating an executable, leave it for libraries +# More information here https://doc.rust-lang.org/cargo/guide/cargo-toml-vs-cargo-lock.html +Cargo.lock + +# These are backup files generated by rustfmt +**/*.rs.bk + +.vscode \ No newline at end of file diff --git a/day2/rust/Cargo.toml b/day2/rust/Cargo.toml new file mode 100644 index 0000000..72614d5 --- /dev/null +++ b/day2/rust/Cargo.toml @@ -0,0 +1,9 @@ +[package] +name = "rust" +version = "0.1.0" +authors = ["Anson "] +edition = "2018" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] diff --git a/day2/rust/src/main.rs b/day2/rust/src/main.rs new file mode 100644 index 0000000..082edb2 --- /dev/null +++ b/day2/rust/src/main.rs @@ -0,0 +1,35 @@ +use std::fs; + +fn main() { + let input = fs::read_to_string("..\\input.txt").expect("Could not read file"); + + let lines: Vec<&str> = input.lines().collect(); + + println!("Part1:"); + let mut valid = 0; + for line in lines.iter() { + let l: Vec<&str> = line.split_whitespace().collect(); + + let min: i32 = l[0].split("-").collect::>()[0] + .parse::() + .unwrap(); + let max: i32 = l[0].split("-").collect::>()[1] + .parse::() + .unwrap(); + + let key: char = l[1].chars().nth(0).unwrap(); + let pass: &str = l[2]; + + let mut count = 0; + for c in pass.chars() { + if c == key { + count += 1; + } + } + if count <= max && count >= min { + valid += 1; + } + } + println!("Valid Passwords: {}\n", valid); + println!("\nPart2:"); +}