This commit is contained in:
JonOfUs 2022-12-02 15:23:41 +01:00
parent fa59ed6875
commit 6ed8d67d9d
5 changed files with 2568 additions and 4 deletions

2
Cargo.lock generated
View file

@ -3,5 +3,5 @@
version = 3
[[package]]
name = "AdventOfCode2022"
name = "advent_of_code2022"
version = "0.1.0"

View file

@ -1,5 +1,5 @@
[package]
name = "AdventOfCode2022"
name = "advent_of_code2022"
version = "0.1.0"
edition = "2021"

2500
res/02/input.txt Normal file

File diff suppressed because it is too large Load diff

64
src/d02.rs Normal file
View file

@ -0,0 +1,64 @@
use std::fs;
pub fn d02() {
let path = "res/02/input.txt";
let contents = fs::read_to_string(path).expect("Should have been able to read the file");
let cont_arr = contents.split("\n");
let mut scores = Vec::<i32>::new();
cont_arr.clone().into_iter().for_each(|line| {
match line {
// A/X: Rock 1
// B/Y: Paper 2
// C/Z: Scissors 3
// LOSE 0
// DRAW 3
// WIN 6
"A X" => scores.push(1 + 3),
"A Y" => scores.push(2 + 6),
"A Z" => scores.push(3 + 0),
"B X" => scores.push(1 + 0),
"B Y" => scores.push(2 + 3),
"B Z" => scores.push(3 + 6),
"C X" => scores.push(1 + 6),
"C Y" => scores.push(2 + 0),
"C Z" => scores.push(3 + 3),
_ => {}
}
});
let sum: i32 = scores.clone().into_iter().sum();
println!("Result 1: {}", sum);
// Task 2
scores.clear();
cont_arr.clone().into_iter().for_each(|line| {
match line {
// A: Rock 1
// B: Paper 2
// C: Scissors 3
// LOSE 0
// DRAW 3
// WIN 6
"A X" => scores.push(3 + 0),
"A Y" => scores.push(1 + 3),
"A Z" => scores.push(2 + 6),
"B X" => scores.push(1 + 0),
"B Y" => scores.push(2 + 3),
"B Z" => scores.push(3 + 6),
"C X" => scores.push(2 + 0),
"C Y" => scores.push(3 + 3),
"C Z" => scores.push(1 + 6),
_ => {}
}
});
let sum: i32 = scores.clone().into_iter().sum();
println!("Result 2: {}", sum);
}

View file

@ -1,5 +1,5 @@
mod d01;
mod d02;
fn main() {
d01::d01();
d02::d02();
}