Given this list List(’A’, ‘B’, ‘C’, ‘D’), return this result:
[A][B][C][D]
[AB][AC][AD][BC][BD][CD]
[ABC][ABD][ACD][BCD]
[ABCD]
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:
return
indices = list(range(r))
yield tuple(pool[i] for i in indices)
whileTrue:
# make sure that we're not doing the base case (e.g. ABCD of Comb('ABCD', 4))