### All possible combinations from list

Hi all, I’m trying to wrap my head around this and am guessing there’s someone who can point me in the right direction.

I’d like to have a list of numbers from 0-7 (the notes of the major scale, in this case) and have an automated way to create every combination of those numbers to store in a coll.

That means:

0, 1, 2, 3, 4, 5, 6, 7

0 1, 0 2… 2 3, 2 4, 5 7, 6 7, etc

0 1 2, 0 1 3, 0 1 4, etc

up to 0 1 2 3 4 5 6 7

I’ve been able to successfully do a small version of this with two counter objects that counts from 0-7, then 1-7, 2-7, and so on. Seems like a start but not exactly what I’m looking for.

Can do this by hand, but doing it automatically is more fun and interesting. Any thoughts appreciated!

Sounds like you want every octal number from 0 to 1234567. 1234567 in octal is the same as 342391 in decimal.

http://www.google.com/search?client=safari&rls=en&q=0o1234567+in+decimal&ie=UTF-8&oe=UTF-8

So, just get a counter to go from 0 to 342391, and then convert from decimal to octal (adding leading zeros if necessary). Here’s the first site I could find about the calculations required to convert from decimal to octal:

http://www.tpub.com/neets/book13/53j.htm

That’s one way to do it anyway. I’m sure there’s another combinatorial way to systematically find every combination.

Sorry to not respond sooner, I’ve been trying to get this working (the basic structure works no problem, formatting and parsing taking a little longer).

Will post the patch this weekend. What I have should be easily changed to convert any decimal number to octal, hexidecimal, etc – something that might be useful to others.

Thanks very much!

Try this little javascript for converting from one base to another.

lh

```
// lh.numeral.js
var inb = jsarguments[1] || 10;
var outb = jsarguments[2] || 2;
basein(inb);
baseout(outb);
function anything() {
outlet(0,parseInt(arrayfromargs(messagename,arguments)[0],inb).toString(outb));
}
function basein(x) {
inb = Math.min(Math.max(2,x),36);
}
function baseout(x) {
outb = Math.min(Math.max(2,x),36);
}
autowatch = 1;
// EOF
```

-- Pasted Max Patch, click to expand. --Copyallof the following text. Then, in Max, selectNew From Clipboard.----------begin_max5_patcher---------- 429.3oc0U10aCBBEF9Z8WAgqcFwu6ta+NVZV7CVkFELJlYWS+uODzU6R5BZW Z5tQjWvCumGNfGMMfordbKD7L3UfgwQSCCozffwXeCXUReVYRqbZPJ9CV5dn kZHNtmKkqaHTNfkwSJmFqNgmUPn6dqAmwUKgaPnsiE.swYnIza3oq3cv1wu4 cFkSSpvxX9RC4bzH4RMwZ+T7jFsqhPKwboyPmEYc7IUmYAtk7oLvHWamA0Sl lCOrtsLeeKnrvVrp3ljR.JDDqA.BikMNAqi.QKf.nqPfQY0L4GpwJGBgfs+c vQUVTf6+Elf1DLiIAQqCIgOxEENhrSCB3KOPfj6Nq.AA+upJRIzjlC+FVPJd DJoSjy5nh+iaggF4tpjHZy5xcuGuJhtpTbiFINRcavJ2zcWPh6tvDWT6Bs.v zD5tKYfzhvRB8m+QUllC5WBlVVWS1TTGcM3bhlia4hiHbBiNaNAWLmBRdNlN uzshjWyDVbzBHWW6fg5nQP5+cuqr8oqWCzvqgKyq2AGEsLGMwK0MPthlod2n Wizvqw2U54ogi7uqNRmSCd2fiDcNY908RWHw -----------end_max5_patcher-----------

You might also look into [&], the bitwise operator, and running the values 0-255 through a series of &:

& 128

& 64

& 32

etc…

which when combined back into lists will give you binary representations of the numbers 0-255. These lists of 00100101 (etc.) can be used to grab numbers from your actual list. I’m not sure what the result will be exactly…will it give every combination? :) [zl mth] with a [sel] can grab the elements of the list, or there are other ways. You also might run the lists into a [matrixctrl] to see the spreads of the "ons" and "offs", and you can always use presets for these too.

To sort the results, look to [zl group] and/or [zl len], and [zl sort], so you can separate the lists by length and get them in ascending order if they’re not already.

Doubtless there are hundreds of ways to go about this… it’s a good question nonetheless.

Forums > MaxMSP