This file contains 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
@n_map = { 1 => "0", 2 => "1", 3 => "2", 4 => "3", 5 => "4", 6 => "5", | |
7 => "6", 8 => "7", 9 => "8", 10 => "9", 11 => "a", 12 => "b", | |
13 => "c", 14 => "d", 15 => "e", 16 => "f", 17 => "g", 18 => "h", | |
19 => "i", 20 => "j", 21 => "k", 22 => "l", 23 => "m", 24 => "n", | |
25 => "o", 26 => "p", 27 => "q", 28 => "r", 29 => "s", 30 => "t", | |
31 => "u", 32 => "v", 33 => "w", 34 => "x", 35 => "y", 36 => "z", | |
37 => "A", 38 => "B", 39 => "C", 40 => "D", 41 => "E", 42 => "F", | |
43 => "G", 44 => "H", 45 => "I", 46 => "J", 47 => "K", 48 => "L", | |
49 => "M", 50 => "N", 51 => "O", 52 => "P", 53 => "Q", 54 => "R", | |
55 => "S", 56 => "T", 57 => "U", 58 => "V", 59 => "W", 60 => "X", | |
61 => "Y", 62 => "Z" } | |
def convert62(i) | |
digit = [] | |
begin | |
i, c = i.divmod(62) | |
digit << @n_map[c+1] | |
end while i > 0 | |
return digit.reverse.join('') | |
end | |
puts convert62(123456) #=> "w7e" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment