
Mar 30th, 2008, 05:55 AM
#1
Thread Starter
New Member
matrice manipulation
i have a matrix 16 by 3 (3 cols 16 rows) all consists of 1's and 0's
i want all the combinations that has only one 1 per row
how can i do that?
example
for
(11
01)
i get
(10
01)
and
(01
01)
etc.
thanx

Mar 30th, 2008, 08:54 AM
#2
Hyperactive Member
Re: matrice manipulation
There are a number of ways to do it, but I want to make sure I understand the question.
Where are you getting the numbers? (1101)? Are these really suppose to be pairs (11,01)?
Will each number always be two digits, or can it be anything, example (1100,101), or just like your example (11,01), which numerically would really be (11,1)
Or is your array strings and not numbers?
What output do you want? Are you looking for a listing of the array members that meet your criteria only?, or just a count of how many there are?
Will every element have at least one "1", or can there be some with none, ... (10,00)?
Finally, when you say 3 columns, 16 rows, how does that relate to the number pair you're getting (11,10).
Give examples of what would be in Row 0, Column 0; Row 0, column 1, Row 0, column 2, Row 1, column 0....etc
Last edited by Caskbill; Mar 30th, 2008 at 09:01 AM.

Mar 31st, 2008, 01:12 AM
#3
Thread Starter
New Member
Re: matrice manipulation
11
10
is a miniature sample
what i really mean is to find all the possible combinations of one 1 in a row (must be only 1 one no more no less)
example
for row 1
101
so this will create
100 and 001
so if i have 111 in all 16 rows
i get all the 43 mil combinations possible! (they will note be stored anywhere just the ones that pass the 'if')
i tried it with 16 nested loops but its too long too ugly, so i'm looking for other way

Mar 31st, 2008, 03:13 AM
#4
Frenzied Member
Re: matrice manipulation
Your input is a matrix with zero to three ones per row and your output should be all possible matrixes with just one one per row obtained by removing ones from the input array.
ie:
11 > 11 > 01
01 > 01 > 01
and
11 > 11 > 10
01 > 01 > 01
Right?
You can express each row as the values of each cell (ie [1,0,0] or [0,1,1]) but also as the locations of the ones. (ie {0} or {1,2})
The input can be written as:
[1,0,0] > {0}
[0,1,1] > {1,2}
[1,0,1] > {0,2}
{1,2} can be viewed as the description of a 'multione' row but also as the possibilities for 'singleone' rows: {1} and {2}
If you convert the matrix from [] notation to {} notation you can loop through the matrix (each row's loop nested within the previous row's loop) and pick each option.
Then the picked options from each row are assembled back into an {} array (with just one option per row) and converted back to [] notation.
Posting Permissions
 You may not post new threads
 You may not post replies
 You may not post attachments
 You may not edit your posts

Forum Rules

Click Here to Expand Forum to Full Width
