I\'ve this familiar question that looks like permutation/combination of the Math world.
How can I achieve the following via ruby?
badges = \"1-2-3\"
Functional approach:
bs = "1-2-3".split("-") strings = 1.upto(bs.size).flat_map do |n| bs.permutation(n).map { |vs| vs.join("-") } end #=> ["1", "2", "3", "1-2", "1-3", "2-1", "2-3", "3-1", "3-2", "1-2-3", "1-3-2", "2-1-3", "2-3-1", "3-1-2", "3-2-1"]