diff --git a/day-12/src/main.rs b/day-12/src/main.rs index 6212c23..dc2ef28 100644 --- a/day-12/src/main.rs +++ b/day-12/src/main.rs @@ -8,10 +8,6 @@ fn main() -> Result<(), Box<dyn std::error::Error>> { let location = simulate_ship_movement(&actions); println!("{}", location.0.abs() + location.1.abs()); - // Part 2 - let location = simulate_waypoint_movement(&actions); - println!("{}", location.0.abs() + location.1.abs()); - Ok(()) } @@ -140,48 +136,6 @@ fn simulate_ship_movement(actions: &Vec<Action>) -> (i64, i64) { coords } -fn simulate_waypoint_movement(actions: &Vec<Action>) -> (i64, i64) { - let mut waypoint = (1, 10); - let mut ship = (0, 0); - - for action in actions { - match *action { - Action::North(amount) => { - waypoint.0 += amount as i64; - } - Action::South(amount) => { - waypoint.0 -= amount as i64; - } - Action::East(amount) => { - waypoint.1 += amount as i64; - } - Action::West(amount) => { - waypoint.1 -= amount as i64; - } - Action::Left(amount) => match amount % 360 { - 0 => {} - 90 => waypoint = (waypoint.1, -waypoint.0), - 180 => waypoint = (-waypoint.0, -waypoint.1), - 270 => waypoint = (-waypoint.1, waypoint.0), - _ => panic!("Only 90 degree turns allowed"), - }, - Action::Right(amount) => match amount % 360 { - 0 => {} - 90 => waypoint = (-waypoint.1, waypoint.0), - 180 => waypoint = (-waypoint.0, -waypoint.1), - 270 => waypoint = (waypoint.1, -waypoint.0), - _ => panic!("Only 90 degree turns allowed"), - }, - Action::Forward(amount) => { - ship.0 += waypoint.0 * amount as i64; - ship.1 += waypoint.1 * amount as i64; - } - } - } - - ship -} - #[cfg(test)] mod tests { use super::*; @@ -204,22 +158,4 @@ mod tests { Ok(()) } - - #[test] - fn test_simple2() -> Result<(), Box<dyn std::error::Error>> { - let input = indoc!( - "F10 - N3 - F7 - R90 - F11 - " - ); - - let actions = parse_actions(&input)?; - let location = simulate_waypoint_movement(&actions); - assert_eq!(location.0.abs() + location.1.abs(), 286); - - Ok(()) - } }