Created
November 12, 2015 18:18
-
-
Save evadnoob/c1da9c43c17cb9840d56 to your computer and use it in GitHub Desktop.
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
static CHARS: &'static str = "0123456789ABCDEFGHIJKLMNPRSTUVWYXZ_abcdefghijkmnopqrstuvwyxz"; | |
fn base60_encode(num: i64) -> String { | |
let mut hash = String::new(); | |
let mut n = num; | |
while n > 0 { | |
let remainder = n % 60; | |
hash.push(CHARS.chars().nth(remainder as usize).expect("expected a character!")); | |
n = (n - remainder) / 60; | |
} | |
hash.rev() | |
} | |
#[test] | |
fn it_works() { | |
println!("base60_encode(1): {}", base60_encode(1)); | |
println!("base60_encode(1000000): {}", base60_encode(1000000)); | |
println!("base60_encode(10450001): {}", base60_encode(110450001)); | |
} | |
~ | |
~ | |
~ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment