Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- data = ('a'..'d').to_a
- N = data.size
- indices = data.map { |_| 0 }
- loop do
- puts((0...N).map { |i| data[indices[i]] }.join(''))
- indices[-1] += 1
- looking_index = N - 1
- while indices[looking_index] == N
- indices[looking_index] = 0
- looking_index -= 1
- return if looking_index < 0
- indices[looking_index] += 1
- end
- end
Add Comment
Please, Sign In to add comment