Day 2
parent
7b19a53f66
commit
ef84a6b863
File diff suppressed because it is too large
Load Diff
|
@ -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,
|
||||
};
|
||||
}
|
|
@ -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,
|
||||
};
|
||||
}
|
Loading…
Reference in New Issue