diff --git a/src/bin/day22.rs b/src/bin/day22.rs
index c37ea9c..0fa5ded 100644
--- a/src/bin/day22.rs
+++ b/src/bin/day22.rs
@@ -96,6 +96,25 @@ lazy_static! {
HashMap::from([((1, 0), 0), ((0, 1), 1), ((-1, 0), 2), ((0, -1), 3)]);
}
+fn solve(wrapper: &impl Wrap, input: &Input) -> Output {
+ let final_state = input
+ .instructions
+ .iter()
+ .fold(State::new(input), |mut state, y| {
+ match &y {
+ Instruction::Move(steps) => state.step(wrapper, *steps),
+ Instruction::TurnLeft => state.turn_left(),
+ Instruction::TurnRight => state.turn_right(),
+ }
+
+ state
+ });
+
+ (1000 * (final_state.y + 1) + 4 * (final_state.x + 1) + DIRECTIONS[&final_state.direction])
+ .try_into()
+ .unwrap()
+}
+
struct Day22;
impl Solution for Day22 {
fn parse_input>(pathname: P) -> Input {
@@ -163,24 +182,7 @@ impl Solution for Day22 {
}
fn part_1(input: &Input) -> Output {
- let wrapper = Wrap2D;
-
- let final_state = input
- .instructions
- .iter()
- .fold(State::new(input), |mut state, y| {
- match &y {
- Instruction::Move(steps) => state.step(&wrapper, *steps),
- Instruction::TurnLeft => state.turn_left(),
- Instruction::TurnRight => state.turn_right(),
- }
-
- state
- });
-
- (1000 * (final_state.y + 1) + 4 * (final_state.x + 1) + DIRECTIONS[&final_state.direction])
- .try_into()
- .unwrap()
+ solve(&Wrap2D, input)
}
fn part_2(_input: &Input) -> Output {