diff --git a/advent_of_code/2022/17/src/main.rs b/advent_of_code/2022/17/src/main.rs index 7ad667c..5cd8eaa 100644 --- a/advent_of_code/2022/17/src/main.rs +++ b/advent_of_code/2022/17/src/main.rs @@ -44,15 +44,15 @@ impl Shape { } } - fn height(&self) -> u32 { - self.left().len() as u32 + fn height(&self) -> u64 { + self.left().len() as u64 } - fn width(&self) -> u32 { - self.under().len() as u32 + fn width(&self) -> u64 { + self.under().len() as u64 } - fn under(&self) -> Vec { + fn under(&self) -> Vec { match self { HorLine => vec![0, 0, 0, 0], Plus => vec![1, 0, 1], @@ -62,7 +62,7 @@ impl Shape { } } - fn left(&self) -> Vec { + fn left(&self) -> Vec { match self { HorLine => vec![0], Plus => vec![1, 0, 1], @@ -72,7 +72,7 @@ impl Shape { } } - fn right(&self) -> Vec { + fn right(&self) -> Vec { match self { HorLine => vec![0], Plus => vec![1, 0, 1], @@ -82,7 +82,7 @@ impl Shape { } } - fn shape(&self) -> Vec<(u32, u32)> { + fn shape(&self) -> Vec<(u64, u64)> { match self { HorLine => vec![(0, 0), (1, 0), (2, 0), (3, 0)], Plus => vec![(1, 0), (0, 1), (1, 1), (2, 1), (1, 2)], @@ -104,8 +104,8 @@ fn parse_input(input: &str) -> IResult<&str, Jets> { Ok((input, jets)) } -fn draw_cave(cave_map: &HashSet<(u32, u32)>, falling_shape: &Shape, shape_coord: &(u32, u32)) { - let shape_coords: Vec<(u32, u32)> = falling_shape +fn draw_cave(cave_map: &HashSet<(u64, u64)>, falling_shape: &Shape, shape_coord: &(u64, u64)) { + let shape_coords: Vec<(u64, u64)> = falling_shape .shape() .iter() .map(|&(x, y)| (shape_coord.0 + x, shape_coord.1 + y)) @@ -134,11 +134,11 @@ fn draw_cave(cave_map: &HashSet<(u32, u32)>, falling_shape: &Shape, shape_coord: } fn fall( - cave_map: &mut HashSet<(u32, u32)>, + cave_map: &mut HashSet<(u64, u64)>, jetstream: &mut Jets, falling_shape: &Shape, - highest_unit: u32, -) -> u32 { + highest_unit: u64, +) -> u64 { let mut rock_coord = (3, highest_unit + 4); let shape_under = falling_shape.under(); let shape_right = falling_shape.right(); @@ -156,7 +156,7 @@ fn fall( if jet_dir == Left { if rock_coord.0 > 1 { let move_result = shape_left.iter().enumerate().any(|(index, &indent)| { - cave_map.contains(&(rock_coord.0 + indent - 1, rock_coord.1 + index as u32)) + cave_map.contains(&(rock_coord.0 + indent - 1, rock_coord.1 + index as u64)) }); if !move_result { rock_coord = (rock_coord.0 - 1, rock_coord.1); @@ -167,7 +167,7 @@ fn fall( let move_result = shape_right.iter().enumerate().any(|(index, &indent)| { cave_map.contains(&( rock_coord.0 + shape_width - indent, - rock_coord.1 + index as u32, + rock_coord.1 + index as u64, )) }); if !move_result { @@ -181,7 +181,7 @@ fn fall( // Then, move the shape down if rock_coord.1 > 1 && !shape_under.iter().enumerate().any(|(index, &indent)| { - cave_map.contains(&(rock_coord.0 + index as u32, rock_coord.1 + indent - 1)) + cave_map.contains(&(rock_coord.0 + index as u64, rock_coord.1 + indent - 1)) }) { rock_coord = (rock_coord.0, rock_coord.1 - 1); @@ -199,11 +199,11 @@ fn fall( } fn main() { - let input_text = include_str!("../input.txt"); + let input_text = include_str!("../test.txt"); let (_rest, mut jetstream) = parse_input(input_text).unwrap(); - let mut number_of_rocks = 2022; - let mut cave_map: HashSet<(u32, u32)> = HashSet::new(); + let mut number_of_rocks: u64 = 1000000000000; + let mut cave_map: HashSet<(u64, u64)> = HashSet::new(); let mut highest_unit = 0; let mut falling_rock = HorLine;