All possible combinations from list

    Dec 17 2009 | 9:54 pm
    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!

    • Dec 17 2009 | 10:07 pm
      Sounds like you want every octal number from 0 to 1234567. 1234567 in octal is the same as 342391 in decimal.
      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:
      That's one way to do it anyway. I'm sure there's another combinatorial way to systematically find every combination.
    • Dec 19 2009 | 3:44 pm
      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!
    • Dec 19 2009 | 8:04 pm
      Try this little javascript for converting from one base to another.
      // lh.numeral.js
      var inb = jsarguments[1] || 10;
      var outb = jsarguments[2] || 2;
      function anything() {
      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
    • Dec 20 2009 | 12:52 am
      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.