Skip to content

Instantly share code, notes, and snippets.

@Nayshins
Created March 13, 2014 02:08
Show Gist options
  • Save Nayshins/9520719 to your computer and use it in GitHub Desktop.
Save Nayshins/9520719 to your computer and use it in GitHub Desktop.
def gen_index(num_ele)
arr = []
num_ele.times do |index|
arr = add_index(arr, index)
end
arr
end
def add_index(arr, index)
arr + arr.reverse.map { |ele| ele.dup << index } << [index]
end
puts "gen 1"
gen_index(1).each {|e| p e}
puts "gen 2"
gen_index(2).each {|e| p e}
puts "gen 3"
gen_index(3).each {|e| p e}
puts "gen 4"
gen_index(4).each {|e| p e}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment