Implement 2025 - Day 1 - Part 2
This commit is contained in:
36
2025/01.rs
36
2025/01.rs
@@ -38,26 +38,44 @@ fn main() {
|
|||||||
|
|
||||||
println!("Rotations: {:#?}", rotations);
|
println!("Rotations: {:#?}", rotations);
|
||||||
|
|
||||||
let mut count = 0;
|
let mut count: usize = 0;
|
||||||
|
|
||||||
let mut state: isize = 50;
|
let mut state: isize = 50;
|
||||||
for rot in rotations.iter() {
|
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 {
|
match rot.direction {
|
||||||
Direction::Left => {
|
Direction::Left => {
|
||||||
state = state.strict_sub_unsigned(rot.amount);
|
if state != 0 && amount > state as usize {
|
||||||
state = state.strict_rem_euclid(100);
|
count += 1;
|
||||||
}
|
}
|
||||||
Direction::Right => {
|
|
||||||
state = state.strict_add_unsigned(rot.amount);
|
|
||||||
state = state.strict_rem_euclid(100);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
println!("Applying {:?} => {}", rot, state);
|
state = state.strict_sub_unsigned(amount);
|
||||||
|
state = state.strict_rem_euclid(100);
|
||||||
|
|
||||||
if state == 0 {
|
if state == 0 {
|
||||||
count += 1;
|
count += 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Direction::Right => {
|
||||||
|
state = state.strict_add_unsigned(amount);
|
||||||
|
if state >= 100 {
|
||||||
|
count += 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
state = state.strict_rem_euclid(100);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
println!("Applying {:?} => {} ({})", rot, state, count);
|
||||||
|
}
|
||||||
|
|
||||||
println!("Result: {}", count);
|
println!("Result: {}", count);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user