aoc2022 day 02

This commit is contained in:
Max Hohlfeld 2022-12-02 09:51:40 +01:00
parent 00ef5ed60e
commit 12ea10cdeb
4 changed files with 2564 additions and 0 deletions

2501
src/aoc2022/day02/input.txt Normal file

File diff suppressed because it is too large Load Diff

59
src/aoc2022/day02/mod.rs Normal file
View File

@ -0,0 +1,59 @@
// Rock
// Paper
// Scissors
pub fn task_one(input: &str) -> String {
let mut total_score = 0;
for line in input.lines() {
let split = line.split_once(' ');
if split.is_some() {
let score = match split.unwrap() {
("A", "X") => 4,
("A", "Y") => 8,
("A", "Z") => 3,
("B", "X") => 1,
("B", "Y") => 5,
("B", "Z") => 9,
("C", "X") => 7,
("C", "Y") => 2,
("C", "Z") => 6,
_ => panic!("Combination is not valid"),
};
total_score += score;
}
}
total_score.to_string()
}
// Loose
// Draw
// Win
pub fn task_two(input: &str) -> String {
let mut total_score = 0;
for line in input.lines() {
let split = line.split_once(' ');
if split.is_some() {
let score = match split.unwrap() {
("A", "X") => 3,
("A", "Y") => 4,
("A", "Z") => 8,
("B", "X") => 1,
("B", "Y") => 5,
("B", "Z") => 9,
("C", "X") => 2,
("C", "Y") => 6,
("C", "Z") => 7,
_ => panic!("Combination is not valid"),
};
total_score += score;
}
}
total_score.to_string()
}

View File

@ -1 +1,2 @@
pub mod day01; pub mod day01;
pub mod day02;

View File

@ -39,4 +39,7 @@ fn main() {
// AOC 2022 // AOC 2022
puzzle = Puzzle { day: 1, year: 2022, task_one: aoc2022::day01::task_one, task_two: aoc2022::day01::task_two }; puzzle = Puzzle { day: 1, year: 2022, task_one: aoc2022::day01::task_one, task_two: aoc2022::day01::task_two };
puzzle.solve_and_print(); puzzle.solve_and_print();
puzzle = Puzzle { day: 2, year: 2022, task_one: aoc2022::day02::task_one, task_two: aoc2022::day02::task_two };
puzzle.solve_and_print();
} }