Code for calculating all possible combinations

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • stephenvr
    New Member
    • Feb 2007
    • 1

    Code for calculating all possible combinations

    Calling on all the mathematical gurus out there. I am looking for a way to automate the process of working out certain possible combinations available for a number of fields, i.e. if I had 1 row of data containing 6 column fields of data in an excel spreadsheet, and I then wanted to empty or change the contents of one or more columns, I would want all the possible combinations to then be worked out automatically. (seem my example at the bottom of this mail)

    Is there an algorithm that I can make use of or does anyone have code for such a calculation. Your assistance would be greatly appreciated.

    Regards

    Stephen van Rooyen

    Example (postal address)

    1 2 3 4 5 6
    | 4 | sable | close | strijdom park | 2169 | randburg |
    | | sable | close | strijdom park | 2169 | randburg |
    | 4 | sable | | strijdom park | 2169 | randburg |
    | 4 | sable | close | strijdom park | | randburg |
    | 4 | sable | close | strijdom park | | |
  • r035198x
    MVP
    • Sep 2006
    • 13225

    #2
    Originally posted by stephenvr
    Calling on all the mathematical gurus out there. I am looking for a way to automate the process of working out certain possible combinations available for a number of fields, i.e. if I had 1 row of data containing 6 column fields of data in an excel spreadsheet, and I then wanted to empty or change the contents of one or more columns, I would want all the possible combinations to then be worked out automatically. (seem my example at the bottom of this mail)

    Is there an algorithm that I can make use of or does anyone have code for such a calculation. Your assistance would be greatly appreciated.

    Regards

    Stephen van Rooyen

    Example (postal address)

    1 2 3 4 5 6
    | 4 | sable | close | strijdom park | 2169 | randburg |
    | | sable | close | strijdom park | 2169 | randburg |
    | 4 | sable | | strijdom park | 2169 | randburg |
    | 4 | sable | close | strijdom park | | randburg |
    | 4 | sable | close | strijdom park | | |
    I do not understand your example. But you also need to be more specific on how you are planning on implementing this. It is easy to write a program that does nCr. Whether or not such a program can help you here depends on how you plan to implement the algorithm which I do not yet understand.

    Comment

    • Ganon11
      Recognized Expert Specialist
      • Oct 2006
      • 3651

      #3
      I think the number of possible combinations is 2^n - 1, where n is the number of columns. Each column has an equal chance of being emptied or not, regardless of whether or not any other column is emptied. However, you specified that at least one column is emptied, you the possibility that all fields remain full is removed (thus, the minus 1).

      Comment

      Working...