Skip to content

Instantly share code, notes, and snippets.

@imouaddine
Created November 19, 2014 21:58
Show Gist options
  • Save imouaddine/436b32408a54952856b4 to your computer and use it in GitHub Desktop.
Save imouaddine/436b32408a54952856b4 to your computer and use it in GitHub Desktop.
def permutations(str, prefix)
if str.length == 0
puts prefix
else
(0).upto(str.length-1) do |i|
permutations(str.slice(0,i)+str.slice(i+1, str.length), prefix + str[i])
end
end
end
puts permutations("abcd", "")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment