master
kalle 2022-12-03 15:32:54 +01:00
parent 7b19a53f66
commit ef84a6b863
3 changed files with 2576 additions and 0 deletions

2500
input/02.txt Normal file

File diff suppressed because it is too large Load Diff

38
src/bin/02_1.rs Normal file
View File

@ -0,0 +1,38 @@
use std::fs;
use anyhow::Result;
fn main() -> Result<()> {
let input = fs::read_to_string("input/02.txt")?;
let score: i32 = input
.split("\n")
.collect::<Vec<&str>>()
.into_iter()
.filter(|s| *s != "")
.map(|s| s.split(" "))
.map(|mut s| (s.next().expect(""), s.next().expect("")))
.map(map_move_to_score)
.sum();
println!("{score}");
return Ok(())
}
// ABC XYZ
fn map_move_to_score(action: (&str, &str)) -> i32 {
return match action {
("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,
(_, _) => 0,
};
}

38
src/bin/02_2.rs Normal file
View File

@ -0,0 +1,38 @@
use std::fs;
use anyhow::Result;
fn main() -> Result<()> {
let input = fs::read_to_string("input/02.txt")?;
let score: i32 = input
.split("\n")
.collect::<Vec<&str>>()
.into_iter()
.filter(|s| *s != "")
.map(|s| s.split(" "))
.map(|mut s| (s.next().expect(""), s.next().expect("")))
.map(map_move_to_score)
.sum();
println!("{score}");
return Ok(())
}
// ABC XYZ
fn map_move_to_score(action: (&str, &str)) -> i32 {
return match action {
("A", "X") => 0 + 3,
("A", "Y") => 3 + 1,
("A", "Z") => 6 + 2,
("B", "X") => 0 + 1,
("B", "Y") => 3 + 2,
("B", "Z") => 6 + 3,
("C", "X") => 0 + 2,
("C", "Y") => 3 + 3,
("C", "Z") => 6 + 1,
(_, _) => 0,
};
}