Here's a recursive solution in Swift to get distinct permutations of a set:
main.swift473 chars21 lines
Here's how you can use this function:
main.swift183 chars6 lines
This function takes a set as input and returns a set of sets, where each set represents a distinct permutation of the original set. The algorithm works by iterating over each element in the set and recursively getting the distinct permutations of the reduced set (i.e. the original set without the current element). We then combine each permutation with the current element to get all possible permutations that include the current element. Finally, we add all these permutations to the result set.
gistlibby LogSnag