pub trait DigitSum: Sized {
// Required method
fn digit_pow_sum(self, base: Self, exp: u32) -> Self;
// Provided method
fn digit_sum(self, base: Self) -> Self { ... }
}
Expand description
桁和。
Examples
use nekolib::math::DigitSum;
assert_eq!(2_u32.pow(15).digit_sum(10), 3 + 2 + 7 + 6 + 8);
assert_eq!(123_u32.digit_pow_sum(10, 2), 1*1 + 2*2 + 3*3);
assert_eq!(0xACE_u32.digit_sum(16), 0xA + 0xC + 0xE);
assert_eq!(12345_u32.digit_pow_sum(10, 0), 5); // the number of digits
assert_eq!(0_u32.digit_pow_sum(10, 0), 1);