This commit is contained in:
Tim Nope
2022-12-11 18:06:33 +01:00
commit 6b6fc8d486
1361 changed files with 19939 additions and 0 deletions

20
d03/src/a1.rs Normal file
View File

@ -0,0 +1,20 @@
pub fn run(inp :Vec<String>) {
let result = inp.iter().map(|elem| {
let tmp = elem.split_at(elem.chars().count() / 2);
for c in tmp.0.chars() {
if tmp.1.contains(c) {
return c.to_ascii_lowercase() as i32 - 'a' as i32 + 1 + if c.is_uppercase() {26} else {0};
}
}
0
}).sum::<i32>();
println!("a1: {}", result);
}

19
d03/src/a2.rs Normal file
View File

@ -0,0 +1,19 @@
pub fn run(inp: Vec<String>) {
let mut sum = 0;
for w in inp.chunks(3) {
'outer: for c in w[0].chars() {
if w[1].contains(c) && w[2].contains(c) {
let a = c.to_ascii_lowercase() as i32 - 'a' as i32
+ 1
+ if c.is_uppercase() { 26 } else { 0 };
sum += a;
break 'outer;
}
}
}
println!("a2: {}", sum);
}

41
d03/src/main.rs Normal file
View File

@ -0,0 +1,41 @@
use std::io::BufRead;
mod a1;
mod a2;
fn read_file(path :&str) -> Vec<String> {
let file = std::fs::File::open(path);
return match file {
Ok(handle) => {
let reader = std::io::BufReader::new(handle);
let mut vec : Vec<String> = vec![];
reader.lines().for_each(|elem| {
vec.push(elem.unwrap());
});
vec
}
Err(_) => vec![]
}
}
fn main() {
let inp :Vec<String> = read_file("input.txt");
a1::run(inp.clone());
a2::run(inp);
}