Tried changing to u64s for day 17 part 2, but you obv need cleverer stuff

This commit is contained in:
2023-01-25 12:42:32 +01:00
parent 824f16527d
commit 86299ba437

View File

@@ -44,15 +44,15 @@ impl Shape {
} }
} }
fn height(&self) -> u32 { fn height(&self) -> u64 {
self.left().len() as u32 self.left().len() as u64
} }
fn width(&self) -> u32 { fn width(&self) -> u64 {
self.under().len() as u32 self.under().len() as u64
} }
fn under(&self) -> Vec<u32> { fn under(&self) -> Vec<u64> {
match self { match self {
HorLine => vec![0, 0, 0, 0], HorLine => vec![0, 0, 0, 0],
Plus => vec![1, 0, 1], Plus => vec![1, 0, 1],
@@ -62,7 +62,7 @@ impl Shape {
} }
} }
fn left(&self) -> Vec<u32> { fn left(&self) -> Vec<u64> {
match self { match self {
HorLine => vec![0], HorLine => vec![0],
Plus => vec![1, 0, 1], Plus => vec![1, 0, 1],
@@ -72,7 +72,7 @@ impl Shape {
} }
} }
fn right(&self) -> Vec<u32> { fn right(&self) -> Vec<u64> {
match self { match self {
HorLine => vec![0], HorLine => vec![0],
Plus => vec![1, 0, 1], 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 { match self {
HorLine => vec![(0, 0), (1, 0), (2, 0), (3, 0)], HorLine => vec![(0, 0), (1, 0), (2, 0), (3, 0)],
Plus => vec![(1, 0), (0, 1), (1, 1), (2, 1), (1, 2)], 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)) Ok((input, jets))
} }
fn draw_cave(cave_map: &HashSet<(u32, u32)>, falling_shape: &Shape, shape_coord: &(u32, u32)) { fn draw_cave(cave_map: &HashSet<(u64, u64)>, falling_shape: &Shape, shape_coord: &(u64, u64)) {
let shape_coords: Vec<(u32, u32)> = falling_shape let shape_coords: Vec<(u64, u64)> = falling_shape
.shape() .shape()
.iter() .iter()
.map(|&(x, y)| (shape_coord.0 + x, shape_coord.1 + y)) .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( fn fall(
cave_map: &mut HashSet<(u32, u32)>, cave_map: &mut HashSet<(u64, u64)>,
jetstream: &mut Jets, jetstream: &mut Jets,
falling_shape: &Shape, falling_shape: &Shape,
highest_unit: u32, highest_unit: u64,
) -> u32 { ) -> u64 {
let mut rock_coord = (3, highest_unit + 4); let mut rock_coord = (3, highest_unit + 4);
let shape_under = falling_shape.under(); let shape_under = falling_shape.under();
let shape_right = falling_shape.right(); let shape_right = falling_shape.right();
@@ -156,7 +156,7 @@ fn fall(
if jet_dir == Left { if jet_dir == Left {
if rock_coord.0 > 1 { if rock_coord.0 > 1 {
let move_result = shape_left.iter().enumerate().any(|(index, &indent)| { 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 { if !move_result {
rock_coord = (rock_coord.0 - 1, rock_coord.1); 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)| { let move_result = shape_right.iter().enumerate().any(|(index, &indent)| {
cave_map.contains(&( cave_map.contains(&(
rock_coord.0 + shape_width - indent, rock_coord.0 + shape_width - indent,
rock_coord.1 + index as u32, rock_coord.1 + index as u64,
)) ))
}); });
if !move_result { if !move_result {
@@ -181,7 +181,7 @@ fn fall(
// Then, move the shape down // Then, move the shape down
if rock_coord.1 > 1 if rock_coord.1 > 1
&& !shape_under.iter().enumerate().any(|(index, &indent)| { && !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); rock_coord = (rock_coord.0, rock_coord.1 - 1);
@@ -199,11 +199,11 @@ fn fall(
} }
fn main() { 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 (_rest, mut jetstream) = parse_input(input_text).unwrap();
let mut number_of_rocks = 2022; let mut number_of_rocks: u64 = 1000000000000;
let mut cave_map: HashSet<(u32, u32)> = HashSet::new(); let mut cave_map: HashSet<(u64, u64)> = HashSet::new();
let mut highest_unit = 0; let mut highest_unit = 0;
let mut falling_rock = HorLine; let mut falling_rock = HorLine;