Given this list List(’A’, ‘B’, ‘C’, ‘D’), return this result:
This link can't be embedded.
This is how one might implement it in python. I got this from the python itertools package, but I didn’t manage to convert it to Coda language. Index incrementing (the highlighted purple part) proved difficult.
def combinations(iterable, r):
# combinations('ABCD', 2) --> AB AC AD BC BD CD
# combinations(range(4), 3) --> 012 013 023 123
pool = tuple(iterable)
poolsz = len(pool)
if r > n:
indices = list(range(r))
yield tuple(pool[i] for i in indices)
# make sure that we're not doing the base case (e.g. ABCD of Comb('ABCD', 4))