How to obtain combinations and permutations of elements

The solution posted by @DavidRutten appears to be doing combinations with replacement.