Skip to content

Instantly share code, notes, and snippets.

@JEG2
Created February 6, 2012 17:56
Show Gist options
  • Select an option

  • Save JEG2/1753683 to your computer and use it in GitHub Desktop.

Select an option

Save JEG2/1753683 to your computer and use it in GitHub Desktop.
s = "james"
substrings = [ ]
s.size.times do |length|
s.split("").permutation(length + 1) do |perm|
if s.include? perm.join
substrings << perm
end
end
end
p substrings
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment