Created
June 29, 2016 23:05
-
-
Save karapetyan/cd0ebeb6df967d8eaaea712984e15173 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
@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