1
$\begingroup$

Not sure on how to migrate a question yet but over on SO someone said I might get better results here. Also please retag as I'm not allowed to create new and might not know the best tagging.

Link to SO question ( Yeah it's the same )

I have 25 individual validations that I need to test all possible combinations, I have seen a couple of questions related to what I'm looking for. The answers suggested something along the lines of using the cartesian product. Would that be the best method for finding the results I'm looking for or is there a better way?

Example:

Think about a 9 by 9 number grid starting from 0 - 9 on the X and Y axis:

|0|1|2|3|4|5|6|7|8|9| |1| |2| |3| |4| |5| |6| |7| |8| |9| 

All the individual validations are boolean ( true = passed, false = failed ).

The X Axis represents all the test results, Example:

|0|1|2|3|4|5|6|7|8|9| |1|T|T|T|T|T|T|T|T|T| |2| |3| |4| |5| |6| |7| |8| |9| 

And the Y Axis represents all the possible combinations, Example:

|0|1|2|3|4|5|6|7|8|9| |1|T|T|T|T|T|T|T|T|T| |2|F|T|T|T|T|T|T|T|T| |3|F|F|T|T|T|T|T|T|T| |4|F|F|F|T|T|T|T|T|T| |5|F|F|F|F|T|T|T|T|T| |6|F|F|F|F|F|T|T|T|T| |7|F|F|F|F|F|F|T|T|T| |8|F|F|F|F|F|F|F|T|T| |9|F|F|F|F|F|F|F|F|T| 

There will be more Y Axis combinations but I hope you get the point.

My question is how would I go about solving all the possible combinations?

  • 0
    Can you explain what exactly you mean when when you say 'solve'?2012-11-08

2 Answers 2

1

So, to write my comment into a full-fledged answer:

There are $512$ rows. Let's look at the possibilities of a single row to understand why: The first element in a row can be either T or F. That's two possibilities. For each of those possibilities, the next one can be either T or F, so that's $2\cdot 2$ possibilities total. Continuing in the same manner, we get $2^9 = 512$ possibilities.

What does a full list look like? Let's start by filling out the first row. For reasons to be explained, I'll label it with a $0$:

|0|T|T|T|T|T|T|T|T|T| 

Now, the way you get from one row to the next is you flip the last value:

|1|T|T|T|T|T|T|T|T|F| 

And every time you flip an F into a T, you also flip the value in front of it:

|2|T|T|T|T|T|T|T|F|T| |3|T|T|T|T|T|T|T|F|F| 

And once again, when you flip an F to a T, you flip the value in front of it, only now it chains to the value in front of that one as well:

|4|T|T|T|T|T|T|F|T|T| 

And you carry on like that until you get to the last row, labeled $511$, with only F's.

This is just counting in binary, really, only with T instead of $0$ and F instead of $1$. The "flipping the value in front" corresponds to carrying (when you go count normally, you do the same thing going from nine to ten). If you do the swap of F-s and T-s into $1$-s and $0$-s, then each row will contain the binary representation of the number in its label.

  • 0
    This is far from the _only_ way to make an exhaustive list, but it is in my opinion the simplest one.2012-11-08
0

I think you need to run a program for that, because there are exactly $2^{9\times 9}=2^{81}$ many variations (this number has 25 decimal digits). Anyway, it is indeed 'cartesian product' of $81$ pieces of the 2 element set $\{True,False\}$.

  • 0
    @Arthur yes you are correct2012-11-08