Skip to content

Instantly share code, notes, and snippets.

@evadnoob
Created November 12, 2015 18:18
Show Gist options
  • Save evadnoob/c1da9c43c17cb9840d56 to your computer and use it in GitHub Desktop.
Save evadnoob/c1da9c43c17cb9840d56 to your computer and use it in GitHub Desktop.
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