Implement 2025 - Day 1 - Part 2

This commit is contained in:
Lol3rrr
2026-01-08 19:42:42 +01:00
parent c7454a0202
commit 4347fb2131

View File

@@ -38,25 +38,43 @@ fn main() {
println!("Rotations: {:#?}", rotations);
let mut count = 0;
let mut count: usize = 0;
let mut state: isize = 50;
for rot in rotations.iter() {
if rot.amount >= 100 {
count += rot.amount / 100;
}
let amount = rot.amount % 100;
if amount == 0 {
continue;
}
match rot.direction {
Direction::Left => {
state = state.strict_sub_unsigned(rot.amount);
if state != 0 && amount > state as usize {
count += 1;
}
state = state.strict_sub_unsigned(amount);
state = state.strict_rem_euclid(100);
if state == 0 {
count += 1;
}
}
Direction::Right => {
state = state.strict_add_unsigned(rot.amount);
state = state.strict_add_unsigned(amount);
if state >= 100 {
count += 1;
}
state = state.strict_rem_euclid(100);
}
};
println!("Applying {:?} => {}", rot, state);
if state == 0 {
count += 1;
}
println!("Applying {:?} => {} ({})", rot, state, count);
}
println!("Result: {}", count);