Created
March 22, 2009 18:14
-
-
Save jackowayed/83245 to your computer and use it in GitHub Desktop.
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
module ShortURL | |
CHARS = [*('a'..'z')] + [*('0'..'9')] | |
def next_after(string) | |
return CHARS[0] if string.empty? | |
if nex = next_char(string[-1].chr) | |
return string[0..-2] + nex | |
end | |
next_after(string[0..-2])+CHARS[0] | |
end | |
#nil if we need to increment. the next char otherwise | |
def next_char(char) | |
CHARS[1 + CHARS.index(char)] | |
end | |
end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment