Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- N = 5
- def permutations digits
- return [0, 1] if digits == 1
- permutations(digits-1).map { |d| [0, d].flatten } +
- permutations(digits-1).reverse.map { |d| [1, d].flatten }
- end
- puts permutations(N).map &:join
Add Comment
Please, Sign In to add comment