Created
December 13, 2013 00:33
-
-
Save Toshakins/7938159 to your computer and use it in GitHub Desktop.
ruby acrobatics
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#recursive lexicographic permutations | |
def perm(str) | |
res = [] | |
if str.length <= 1 | |
return res << str | |
else | |
t = [] | |
str.each_char do |chr| | |
t += perm(str.delete(chr)) | |
t.each do |permutation| | |
res << chr + permutation unless permutation.include?(chr) | |
end | |
end | |
end | |
return res | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment