aoc2022 day 02
This commit is contained in:
parent
00ef5ed60e
commit
12ea10cdeb
2501
src/aoc2022/day02/input.txt
Normal file
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
59
src/aoc2022/day02/mod.rs
Normal 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()
|
||||||
|
}
|
@ -1 +1,2 @@
|
|||||||
pub mod day01;
|
pub mod day01;
|
||||||
|
pub mod day02;
|
||||||
|
@ -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();
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user