473,322 Members | 1,781 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

Generating a matrix with all possible combinations of values

RSH
Okay my math skills aren't waht they used to be...

With that being said what Im trying to do is create a matrix that given x
number of columns, and y number of possible values i want to generate a two
dimensional array of all possible combinations of values.

A simple example:
2 - columns and 2 possible values would generate:

0 0
1 0
0 1
1 1

I obviously need to generate considerably more complex grids but Imagine the
math would be the same.

Thanks for any assistance!
Ron
Oct 11 '07 #1
4 7614
Hi,

And how you want to keep it?

By using a recursive method this is simple. you can do a similar ting with a
nested number of loops ( in case you know the dimension beforehand)

"RSH" <wa*************@yahoo.comwrote in message
news:%2****************@TK2MSFTNGP05.phx.gbl...
Okay my math skills aren't waht they used to be...

With that being said what Im trying to do is create a matrix that given x
number of columns, and y number of possible values i want to generate a
two dimensional array of all possible combinations of values.

A simple example:
2 - columns and 2 possible values would generate:

0 0
1 0
0 1
1 1

I obviously need to generate considerably more complex grids but Imagine
the math would be the same.

Thanks for any assistance!
Ron

Oct 11 '07 #2
Ron,

Well, the total number of values is going to be the number of values,
taken to the power of the number of columns that can contain those values.
In this case, it is 2 (number of possible values, true/false) squared (the
number of variables) which gives you four.

If you had three columns, you would have 8 possible combinations.

To represent this in code, you just need a two-dimensional array, like
so, where the first dimension is wich combination of values you want, and
the second column is the actual value in that combination. Using the two
values, three variable approach, you would want an 8x3 array, like so:

int rows = 8;
int columns = 3;

bool[,] matrix = new bool[rows, columns];

To initialize the array, the easiest way to populate it would be to use
a recursive algorithm, as Ignacio suggests.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"RSH" <wa*************@yahoo.comwrote in message
news:%2****************@TK2MSFTNGP05.phx.gbl...
Okay my math skills aren't waht they used to be...

With that being said what Im trying to do is create a matrix that given x
number of columns, and y number of possible values i want to generate a
two dimensional array of all possible combinations of values.

A simple example:
2 - columns and 2 possible values would generate:

0 0
1 0
0 1
1 1

I obviously need to generate considerably more complex grids but Imagine
the math would be the same.

Thanks for any assistance!
Ron

Oct 11 '07 #3
RSH wrote:
Okay my math skills aren't waht they used to be...

With that being said what Im trying to do is create a matrix that given x
number of columns, and y number of possible values i want to generate a two
dimensional array of all possible combinations of values.

A simple example:
2 - columns and 2 possible values would generate:

0 0
1 0
0 1
1 1

I obviously need to generate considerably more complex grids but Imagine the
math would be the same.
In addition to what other people have said, note that your matrices
generated will contain potentially redundant values (depending on your
intended use). In terms of unique number combinations, (0 and 1) and (1
and 0) are the same.

This of course only matters if you don't care about position in the matrix.

Chris.
Oct 11 '07 #4
RSH
I suppose I could use a datatable as an output. I used a simple binary flag
as the value array, but in reality I could have x number of values and x
number of rows which for some reason Im hanging up on. As far as the
position within the matrix, that isn't important, I just need to ensure that
every row is unique and that I have all possible permientations accounted
for.

A more realistic sample would be say I have 3 columns (Database1 Value,
Database 2 Value, Form Value)
Then 6 possible values (DBNull.Value,
"Weekly","Bi-Weekly","Semi-Monthly","Monthly","Quarterly")

I need to be able to pump this in to my algorithm and out put a datatable
where I ultimately will make a logi decision table out of it probably using
binary math.

Thanks for the replies!
Ron

"Chris Shepherd" <ch**@nospam.chsh.cawrote in message
news:%2****************@TK2MSFTNGP03.phx.gbl...
RSH wrote:
>Okay my math skills aren't waht they used to be...

With that being said what Im trying to do is create a matrix that given x
number of columns, and y number of possible values i want to generate a
two dimensional array of all possible combinations of values.

A simple example:
2 - columns and 2 possible values would generate:

0 0
1 0
0 1
1 1

I obviously need to generate considerably more complex grids but Imagine
the math would be the same.

In addition to what other people have said, note that your matrices
generated will contain potentially redundant values (depending on your
intended use). In terms of unique number combinations, (0 and 1) and (1
and 0) are the same.

This of course only matters if you don't care about position in the
matrix.

Chris.

Oct 11 '07 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

15
by: christopher diggins | last post by:
Here is some code I wrote for Matrix multiplication for arbitrary dimensionality known at compile-time. I am curious how practical it is. For instance, is it common to know the dimensionality of...
4
by: the hotshot | last post by:
hello, this seems to be a hard question so far and noone has been able to help with this. is it possible to have access start an autonumber with a prefix according to the year when the data is...
16
by: Martin Jørgensen | last post by:
Hi, I've made a program from numerical recipes. Looks like I'm not allowed to distribute the source code from numerical recipes but it shouldn't even be necessary to do that. My problem is...
16
by: akameswaran | last post by:
Ok, this is really irritating me. I'm sure there are different ways of doing this - I'm interested in the algo, not the practical solution, I'm more trying to play with iterators and recursion. I...
8
by: Mir Nazim | last post by:
Hello, I need to write scripts in which I need to generate all posible unique combinations of an integer list. Lists are a minimum 12 elements in size with very large number of possible...
1
by: dancestar2006 | last post by:
I'm trying to write a program that can do the following: it takes 3 inputs: ex. 2000, 1000, 1000 it takes one more input called the total: ex. 6000 it should output that...
21
by: =?UTF-8?B?TWFydGluIFDDtnBwaW5n?= | last post by:
Hello, I´m using a very large 2-dimensional double matrix (45.000x45.000) in my program. At the initialization of the matrix: double matrix = new double I am getting an out of memory...
6
by: py_genetic | last post by:
Hi, I'm looking to generate x alphabetic strings in a list size x. This is exactly the same output that the unix command "split" generates as default file name output when splitting large...
14
by: bjorklund.emil | last post by:
Hello pythonistas. I'm a newbie to pretty much both programming and Python. I have a task that involves writing a test script for every possible combination of preference settings for a software...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.