Skip to content

Instantly share code, notes, and snippets.

@jackowayed
Created March 22, 2009 18:14
Show Gist options
  • Save jackowayed/83245 to your computer and use it in GitHub Desktop.
Save jackowayed/83245 to your computer and use it in GitHub Desktop.
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