Skip to content

Instantly share code, notes, and snippets.

Created March 3, 2014 00:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/9316270 to your computer and use it in GitHub Desktop.
Save anonymous/9316270 to your computer and use it in GitHub Desktop.
ENCODE_CHARS = [*?a..?z, *?A..?Z]
def encode(n)
6.times.map { |i|
n, mod = n.divmod(ENCODE_CHARS.size)
ENCODE_CHARS[mod]
}.join
end
def encode_simplified(n)
result = ""
6.times do
m = n % ENCODE_CHARS.size
n = n / ENCODE_CHARS.size
result << ENCODE_CHARS[m]
end
return result
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment