Guest User

Untitled

a guest
May 23rd, 2018
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.33 KB | None | 0 0
  1. data = ('a'..'d').to_a
  2. N = data.size
  3.  
  4. indices = data.map { |_| 0 }
  5.  
  6. loop do
  7. puts((0...N).map { |i| data[indices[i]] }.join(''))
  8. indices[-1] += 1
  9. looking_index = N - 1
  10. while indices[looking_index] == N
  11. indices[looking_index] = 0
  12. looking_index -= 1
  13. return if looking_index < 0
  14. indices[looking_index] += 1
  15. end
  16. end
Add Comment
Please, Sign In to add comment