Guest User

Untitled

a guest
Jul 18th, 2018
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.21 KB | None | 0 0
  1. N = 5
  2.  
  3. def permutations digits
  4. return [0, 1] if digits == 1
  5. permutations(digits-1).map { |d| [0, d].flatten } +
  6. permutations(digits-1).reverse.map { |d| [1, d].flatten }
  7. end
  8.  
  9. puts permutations(N).map &:join
Add Comment
Please, Sign In to add comment