aboutsummaryrefslogtreecommitdiffstats
path: root/AoC2022
diff options
context:
space:
mode:
Diffstat (limited to 'AoC2022')
-rw-r--r--AoC2022/02/solver.rs38
1 files changed, 38 insertions, 0 deletions
diff --git a/AoC2022/02/solver.rs b/AoC2022/02/solver.rs
index 2fd1e62..dc47354 100644
--- a/AoC2022/02/solver.rs
+++ b/AoC2022/02/solver.rs
@@ -96,9 +96,47 @@ fn solver(strategy: &dyn Fn(&str, Hand) -> Hand) -> u32 {
}
})
}
+// Super simple strategies
+fn fixed_plays2(line: &str) -> u32 {
+ match line {
+ "A X" => 3 + 1, // draw rock
+ "A Y" => 6 + 2, // win paper
+ "A Z" => 0 + 3, // loose scissors
+ "B X" => 0 + 1, // loose rock
+ "B Y" => 3 + 2, // draw paper
+ "B Z" => 6 + 3, // win scissors
+ "C X" => 6 + 1, // win rock
+ "C Y" => 0 + 2, // loose paper
+ "C Z" => 3 + 3, // draw scissors
+ &_ => panic!("Invalid play"),
+ }
+}
+fn reactive_plays2(line: &str) -> u32 {
+ match line {
+ "A X" => 0 + 3, // loose scissors
+ "A Y" => 3 + 1, // draw paper
+ "A Z" => 6 + 2, // win
+ "B X" => 0 + 1, // loose
+ "B Y" => 3 + 2, // draw
+ "B Z" => 6 + 3, // win
+ "C X" => 0 + 2, // loose
+ "C Y" => 3 + 3, // draw
+ "C Z" => 6 + 1, // win
+ &_ => panic!("Invalid play"),
+ }
+}
+fn solver2(strategy: &dyn Fn(&str) -> u32) -> u32 {
+ let file = fs::File::open("input").unwrap();
+ io::BufReader::new(file)
+ .lines()
+ .map(|x| strategy(&x.unwrap()))
+ .sum()
+}
fn main() {
assert_eq!(12535, solver(&fixed_plays));
assert_eq!(15457, solver(&reactive_plays));
+ assert_eq!(12535, solver2(&fixed_plays2));
+ assert_eq!(15457, solver2(&reactive_plays2));
println!("All test passed.")
}