I tried a little bit to implement the Java example in Pd, but couldn't get my brain to wrap around it yet. There is an excellent example of data flow recursion in iem [list-drip] of the list-abs library. Therefore i guess that there must be a very elegant way to do it.
]]>Step 1 is the hardest part; the rest is fairly trivial. Once this is built, you can iterate through as many (decimal) numbers as you like using [until] or [uzi].
]]>Of course, using arrays requires that the list in step 2 consists of only numbers, not symbols. I have some ideas for achieving this too, which I can share if you decide to take the approach I've described.
]]>I hope it's of any help.
]]>I think that a way to do it would be to convert the original list to unique floats (so that list 'a b c' becomes '1 2 3'), get all the permutations of that and then scan each permutation and convert each value back to its corresponding original one. In this case, list 'a a a' would give 6 identical permutations. Is that what you are looking for?
I'm pretty sure it can be done with [list-find] and [list-idx], I'll try and update the patch in the next few days.
]]>The number of all combinations is n^n. On my computer it worked with a list of six elements, but crashed Pd with a list of seven.
Input: abc
Output: aaa, aab, aac, aba, abb, abc, aca, acb, acc, baa, bab, bac, bba, bbb, bbc, bca, bcb, bcc, caa, cab, cac, cba, cbb, cbc, cca, ccb, ccc
combinations.pd (old)
combinations-help.pd (old)
It basically just counts up in an n-ary numeral system, n being the length of the list.
]]>It can output the results in variable length, which can be set via creation argument or right inlet. If no length is provided, the results will have the same length as the original.
Input: abc
Output of [combinations]:
aaa, aab, aac, aba, abb, abc, aca, acb, acc, baa, bab, bac, bba, bbb, bbc, bca, bcb, bcc, caa, cab, cac, cba, cbb, cbc, cca, ccb, ccc
Input: abcd
Output of [combinations 2]:
aa, ab, ac, ad, ba, bb, bc, bd, ca, cb, cc, cd, da, db, dc, dd
Input: ab
Output of [combinations 4]:
aaaa, aaab, aaba, aabb, abaa, abab, abba, abbb, baaa, baab, baba, babb, bbaa, bbab, bbba, bbbb
The right outlet sends a bang when the generation is complete.
combinations.pd
combinations-help.pd
How it works:
Internally, the patch uses lists of numbers 0, 1, ..., n-1; n being the length of the original list. These numbers serve as digits of an n-ary system. It starts with a list of zeros. The digits of each list are send to the right branch (output) and the left branch (iteration) of the patch.
At each iteration, one is added to the first digit of the list. If the result equals n [mod] sets it to zero and [div] takes the carry-over (1) to the next digit. If there is still a carry-over after the last operation, meaning that the current combination is the last one, the spigot is closed and it stops.
Before the output, the internal digits of each list are replaced with the numbers or symbols of the original list. Zero is replaced with the first element, one with the second and so on.
After each iteration a delay 0 is used to brake the loop and avoid stack overflow.
Uses [list-drip] from list-abs extension.
]]>