Skip to content

Instantly share code, notes, and snippets.

@karapetyan
Created June 29, 2016 23:05
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 karapetyan/cd0ebeb6df967d8eaaea712984e15173 to your computer and use it in GitHub Desktop.
Save karapetyan/cd0ebeb6df967d8eaaea712984e15173 to your computer and use it in GitHub Desktop.
@chars = ("A".."Z").to_a
def increase_discharge(str, d)
if str[-d] == @chars.last
str[-d] = @chars.first
increase_discharge(str, d+1)
else
if str[-d].nil?
str.insert(0, @chars.first)
else
str[-d] = @chars[(@chars.find_index(str[-d])+1)]
end
end
str
end
def generate_names(n)
result = []
current = "A"
(n-1).times {
current = increase_discharge(current, 1)
puts current # => B,C,D,E
result << current # => E,E,E,E ????????
}
result
end
puts generate_names(100)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment