This commit is contained in:
2020-12-02 17:46:54 +01:00
parent 0ed6cc7667
commit 23e0a93f63
6 changed files with 1075 additions and 0 deletions

BIN
.DS_Store vendored Normal file

Binary file not shown.

BIN
01/.DS_Store vendored Normal file

Binary file not shown.

1000
02/input.txt Normal file

File diff suppressed because it is too large Load Diff

BIN
02/main Executable file

Binary file not shown.

55
02/main.rs Normal file
View File

@@ -0,0 +1,55 @@
use std::fs::File;
use std::io::{self, prelude::*, BufReader};
fn main() {
// to make this work i had to do the return io::Result thing. i will look into this later of
// how to properly do it
let file = File::open("./input.txt").expect("something");
let reader = BufReader::new(file);
let mut invalidCheck = 0;
for line in reader.lines() {
invalidCheck += checkValidLine(line.unwrap());
println!("{}", invalidCheck);
}
println!("{} valid pwds", invalidCheck);
}
fn checkValidLine(input: String) -> i32 {
let strings = input.split(" ").collect::<Vec<&str>>();
let mut count = 0;
let maxMinString = strings[0].split("-").collect::<Vec<&str>>();
let min = maxMinString[0].parse::<u32>().unwrap() -1;
let max = maxMinString[1].parse::<u32>().unwrap() -1;
let chr = strings[1].chars().nth(0).unwrap();
let chars = strings[2].chars().collect::<Vec<char>>();
if (chars.len() < max as usize) || (chars.len() < min as usize) {
return 0;
}
if (chars[min as usize] == chr && chars[max as usize] != chr) || (chars[min as usize] != chr && chars[max as usize] == chr) {
return 1;
}
return 0;
// for c in strings[2].chars() {
// if c == chr {
// count+=1;
// if count > max {
// println!("too high {}", input);
// return 0;
// }
// }
// }
// if count < min {
// println!("too low: {}", input);
// return 0;
// }
//
// return 1;
}

20
02/readme.md Normal file
View File

@@ -0,0 +1,20 @@
# TODO
Fix the typing thing. better loops
# Task 1
i feel like a dumbass. It's pretty straight forward, however:
loop through each string, parse each string correctly (get max and min amounts and the char). then loop through the
final char, every time a char compare is true, add to the count, if count is bigger then max we can quit before hand.
afterwards in the end check if lower then min.
mainly forgot that it was amount of valid instead of invalid. So....
# Task 2
since i already have the string converted as an array, just a matter of utilizing the usize and int types correctly.
Which i truly didnt, i will also have to come back to this later to improve it.