Last active
August 29, 2015 14:26
-
-
Save oal/9ffce9d03fec4b005d6f to your computer and use it in GitHub Desktop.
Takes a number like 234908571 and returns the digits it contains as a Vec<u8>: [2, 3, 4, 9, 0, 8, 5, 7, 1]
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fn digitize(n: u64) -> Vec<u8> { | |
let mut places = 0; | |
let mut ndiv = n; | |
while ndiv > 0 { | |
ndiv /= 10; | |
places += 1; | |
} | |
let mut digits = Vec::new(); | |
let mut nsub = n; | |
for i in (0..places) { | |
let p = places-i-1; | |
let base = num::pow(10, p); | |
let mut digit = 0; | |
while nsub >= base { | |
nsub -= base; | |
digit += 1; | |
} | |
digits.push(digit); | |
} | |
digits | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment