Day 2, Part 1 & 2

This commit is contained in:
Aadi Desai 2023-10-11 11:36:48 +01:00
parent 2683576b71
commit 77ee459c88
Signed by: supleed2
SSH key fingerprint: SHA256:CkbNRs0yVzXEiUp2zd0PSxsfRUMFF9bLlKXtE1xEbKM
2 changed files with 2547 additions and 0 deletions

47
src/bin/d2.rs Normal file
View file

@ -0,0 +1,47 @@
const INPUT: &str = include_str!("../input/d2.txt");
fn main() -> anyhow::Result<()> {
let score_p1 = INPUT
.as_bytes()
.chunks(4)
.map(|l| play_points(l[0] as char, l[2] as char))
.sum::<usize>();
println!("{score_p1:?}");
let score_p2 = INPUT
.as_bytes()
.chunks(4)
.map(|l| result_points(l[0] as char, l[2] as char))
.sum::<usize>();
println!("{score_p2:?}");
anyhow::Ok(())
}
fn play_points(opponent: char, player: char) -> usize {
match (opponent, player) {
('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,
_ => unreachable!(),
}
}
fn result_points(opponent: char, result: char) -> usize {
match (opponent, result) {
('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,
_ => unreachable!(),
}
}

2500
src/input/d2.txt Normal file

File diff suppressed because it is too large Load diff