3 ms·
The rust NonZeroU64 solution has a subtle 'bug' that happens not to matter. The function fn get_optional_non_zero(n: u64) -> Option<NonZeroU64> l
by rocqua 4y ago
The rust NonZeroU64 solution has a subtle 'bug' that happens not to matter.
The function
fn get_optional_non_zero(n: u64) -> Option<NonZeroU64>
let i = n & 0xFF;
if i == MAGIC { None } else { NonZeroU64::new(i) }
}
Actually returns None for n = 0 or n is any multiple of 256.
The resulting usage in the sum still yields the same result, because skipping zeros in an addition doesn't matter, but it is a subtle difference between this get-function compared to all of the others. It also doubles the number of None cases the code needs to handle.