2022 day 22 part 2

This commit is contained in:
Maciej Jur 2022-12-22 20:14:32 +01:00
parent fb595271bd
commit abb34e8d23

View file

@ -1,3 +1,4 @@
#![allow(dead_code)]
use std::collections::HashMap;
use regex::Regex;
use crate::utils;
@ -158,7 +159,8 @@ impl<'a> Dungeon<'a> {
}
fn solve1((start, map, commands): &(Point, Map, Commands)) -> usize {
let mut dungeon = Dungeon::new(map, *start, Facing::R, Box::new(WrappingPosProvider::new(&map)));
let npp = Box::new(WrappingPosProvider::new(&map));
let mut dungeon = Dungeon::new(map, *start, Facing::R, npp);
for action in commands {
dungeon.act(action)
};
@ -179,10 +181,10 @@ impl NextPosProvider for HardcodedCubeProvider {
(0, 50..=99, U) => ((pos.1 + 100, 0), R), // (0,50) -> (150,0)
(0, 100..=149, U) => ((199, pos.1 - 100), U), // (0,100) -> (199,0)
(0..=49, 50, L) => ((149 - pos.0, 0), R), // (0,50) -> (149,0)
(0..=49, 149, R) => todo!(),
(49, 100..=149, D) => todo!(),
(0..=49, 149, R) => ((149 - pos.0, 99), L), // (0,149) -> (149, 99)
(49, 100..=149, D) => ((pos.1 - 50, 99), L), // (49, 100) -> (50, 99)
(50..=99, 50, L) => ((100, pos.0 - 50), D), // (50,50) -> (100,0)
(50..=99, 99, R) => todo!(),
(50..=99, 99, R) => ((49, pos.0 + 50), U), // (50, 99) -> (49,100)
(100, 0..=49, U) => ((pos.1 + 50, 50), R), // (100,0) -> (50,50)
(100..=149, 0, L) => ((149 - pos.0, 50), R), // (100,0) -> (49, 50)
(100..=149, 99, R) => ((149 - pos.0, 149), L), // (100, 99) -> (49, 149)
@ -196,7 +198,8 @@ impl NextPosProvider for HardcodedCubeProvider {
}
fn solve2((start, map, commands): &(Point, Map, Commands)) -> usize {
let mut dungeon = Dungeon::new(map, *start, Facing::R, Box::new(HardcodedCubeProvider::new()));
let npp = Box::new(HardcodedCubeProvider::new());
let mut dungeon = Dungeon::new(map, *start, Facing::R, npp);
for action in commands {
dungeon.act(action)
};