diff --git a/src/day14.rs b/src/day14.rs index a9fe443..362888a 100644 --- a/src/day14.rs +++ b/src/day14.rs @@ -94,9 +94,10 @@ pub fn part2(input: &str) -> i32 { for seconds in 0..WIDTH as u16 { let mut x_sum = 0; for i in 0..500 { - let px = pxs[i] as u16; - let vx = vxs[i] as u16; - x_sum += ((px + (vx * seconds)) % WIDTH as u16).abs_diff(WIDTH as u16 / 2); + let px = pxs[i]; + let vx = vxs[i]; + pxs[i] = (px + vx) % WIDTH as u8; + x_sum += px.abs_diff(WIDTH as u8 / 2) as u16; } if x_sum < x_min_value { x_min_value = x_sum; @@ -110,9 +111,10 @@ pub fn part2(input: &str) -> i32 { for seconds in 0..HEIGHT as u16 { let mut y_sum = 0; for i in 0..500 { - let py = pys[i] as u16; - let vy = vys[i] as u16; - y_sum += ((py + (vy * seconds)) % HEIGHT as u16).abs_diff(HEIGHT as u16 / 2); + let py = pys[i]; + let vy = vys[i]; + pys[i] = (py + vy) % HEIGHT as u8; + y_sum += py.abs_diff(HEIGHT as u8 / 2) as u16; } if y_sum < y_min_value { y_min_value = y_sum;