Skip to content

Instantly share code, notes, and snippets.

@muhammadn
Last active August 29, 2015 14:06
Show Gist options
  • Save muhammadn/95cc064c6b4f4be65af2 to your computer and use it in GitHub Desktop.
Save muhammadn/95cc064c6b4f4be65af2 to your computer and use it in GitHub Desktop.
lexicographical permutations
Question
Input:
2
3
1
Output:
abc
acb
bac
bca
cab
cba
a
# my answer
('a'..'c').to_a.permutation.map(&:join)
# result
# => ["abc", "acb", "bac", "bca", "cab", "cba"]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment