Day 22, part 2
This commit is contained in:
@ -9,7 +9,7 @@ pub fn main() {
|
||||
// dbg!(&grid);
|
||||
// dbg!(&instructions);
|
||||
|
||||
let mut pose = day22::Pose::new(&grid);
|
||||
let mut pose = grid.initial_pose();
|
||||
// dbg!(&pose);
|
||||
for inst in &instructions {
|
||||
pose = grid.exec_instruction(&pose, inst).0;
|
||||
|
||||
40
src/bin/d22p2.rs
Normal file
40
src/bin/d22p2.rs
Normal file
@ -0,0 +1,40 @@
|
||||
use std::collections::HashMap;
|
||||
|
||||
use aoc22::{
|
||||
day22::{self, CubeSide, Navigable},
|
||||
util,
|
||||
};
|
||||
|
||||
pub fn main() {
|
||||
let (grid, instructions) = day22::parse_map_and_path(&util::parse_input());
|
||||
|
||||
let mut pattern = HashMap::new();
|
||||
pattern.insert(CubeSide::Top, (0, 1));
|
||||
pattern.insert(CubeSide::Fore, (1, 1));
|
||||
pattern.insert(CubeSide::Left, (2, 0));
|
||||
pattern.insert(CubeSide::Back, (3, 0));
|
||||
pattern.insert(CubeSide::Bottom, (2, 1));
|
||||
pattern.insert(CubeSide::Right, (0, 2));
|
||||
|
||||
// Pattern for example input
|
||||
// WARNING: CubeGrid::wrap_around is hardcoded for the pattern above
|
||||
// pattern.insert(CubeSide::Top, (0, 2));
|
||||
// pattern.insert(CubeSide::Fore, (1, 2));
|
||||
// pattern.insert(CubeSide::Left, (1, 1));
|
||||
// pattern.insert(CubeSide::Back, (1, 0));
|
||||
// pattern.insert(CubeSide::Bottom, (2, 2));
|
||||
// pattern.insert(CubeSide::Right, (2, 3));
|
||||
|
||||
let grid = day22::CubeGrid::from(&grid, &pattern);
|
||||
let mut pose = grid.initial_pose();
|
||||
for inst in &instructions {
|
||||
pose = grid.exec_instruction(&pose, inst).0;
|
||||
}
|
||||
let pos = pose.1.pos;
|
||||
let row_add = pattern[&pose.0].0 * grid.side_height;
|
||||
let col_add = pattern[&pose.0].1 * grid.side_width;
|
||||
|
||||
let pass =
|
||||
1000 * (row_add + pos.0 + 1) + 4 * (col_add + pos.1 + 1) + (pose.1.orientation as usize);
|
||||
println!("Passowrd: {}", pass);
|
||||
}
|
||||
Reference in New Issue
Block a user