Skip to content

Commit

Permalink
what about u8s?
Browse files Browse the repository at this point in the history
  • Loading branch information
Icerath committed Dec 15, 2024
1 parent 18b3eb8 commit 8a29a01
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions src/day14.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down

0 comments on commit 8a29a01

Please sign in to comment.