|
|
|
@ -1,6 +1,5 @@ |
|
|
|
|
|
|
|
|
|
/* |
|
|
|
|
uint ulong_len(ulong n) { // get the digit length of a number
|
|
|
|
|
uint ulong_len(ulong n) { // get the nth_digit length of a number
|
|
|
|
|
int len = 0; |
|
|
|
|
while (n != 0) { |
|
|
|
|
n = n / 10; |
|
|
|
@ -10,7 +9,7 @@ uint ulong_len(ulong n) { // get the digit length of a number |
|
|
|
|
} |
|
|
|
|
*/ |
|
|
|
|
|
|
|
|
|
fn digit(num: u64, idx: u32) -> u8 { |
|
|
|
|
fn nth_digit(num: u64, idx: u32) -> u8 { |
|
|
|
|
// ((num % (10**(idx+1))) - (num % (10**idx)))/(10**idx)
|
|
|
|
|
(((num % (10_u64.pow(idx+1))) - (num % (10_u64.pow(idx))))/(10_u64.pow(idx))) as u8 |
|
|
|
|
} |
|
|
|
@ -35,11 +34,9 @@ pub fn number_to_vec(num: u64) -> Vec<u8> { |
|
|
|
|
let len = numlen(num); |
|
|
|
|
|
|
|
|
|
for idx in 0..len { |
|
|
|
|
let digit = digit(num, idx as u32); |
|
|
|
|
let digit = nth_digit(num, idx as u32); |
|
|
|
|
out.push(digit);
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
println!("{:?}", out); |
|
|
|
|
|
|
|
|
|
out |
|
|
|
|
} |
|
|
|
|