Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
armstrong-numbers: add larger testcases (#1601)
Add some extra Armstrong number tests for larger numbers. In particular, the ten-digit solutions can cause naive solutions to overflow; it might be reasonable to gate them behind a feature flag or bonus exercise. The test case 4106098957 is particularly interesting: if the addition is done using `wrapping_add`, this number will appear as an Armstrong number, even though it really isn't. This is because the sum is equal to exactly 2^32 + 4106098957. This might be a worthwhile testcase to add to other languages too to check for overflow bugs. (Rust should panic in debug mode, but this will also catch folks who try to use wrapping_add to get around the panic). The example needs to be updated to handle wrapping properly. Use checked_add to gracefully handle the case where the sum overflows. Note that the individual powers cannot overflow (9^10 < 2^32).
- Loading branch information