I have many arrays A of varying length. For any given A, I'd like to find all the unique sets of three elements of A. For example, if A has five elements:

`A = [5 6 2 4 7];`

one combination of three elements in A is [5 6 2], another combination is [5 6 4], and so on. When I work this out manually I get these combinations:

`5 6 2 5 6 4 5 6 75 2 4 5 2 75 4 7 6 2 4 6 2 7 6 4 7 2 4 7`

The appearance of the solutions above makes me think there may be a clever way to use an identity matrix, but I can't quite think of how. Or perhaps there's a way to use perms, perhaps with sort and unique?

Can you think of a way to get all 3-element subsets of an array?

## Best Answer