Link to home
Start Free TrialLog in
Avatar of JReam
JReamFlag for United States of America

asked on

I need an assist with a programming logic math question.

I need an assist with a programming logic math question.
Here is a simple array of 8 rows &  8 cols.   True/false 1/0

I need to find the group of 8 RnCn's which are all 0's, but do not share the same R or C , i.e. no horizontal or vertical duplicates.

I had to figure this out manually.  There are 2 groups left, then the array will be all 1s.

1st remaining group is:     R1C7   R2C4   R3C3  R4C6  R5C5  R6C2  R7C1  R8C8
2nd remaining group is:    R1C8   R2C2   R3C6  R4C4  R5C3  R6C1  R7C7  R8C5

The QUESTION is:  Can you share with me how to program code (such as VBA or VS)  to find these 2 groups ??

  1  1  1  1  1  1  0  0 
  1  0  1  0  1  1  1  1 
  1  1  0  1  1  0  1  1 
  1  1  1  0  1  0  1  1 
  1  1  0  1  0  1  1  1 
  0  0  1  1  1  1  1  1 
  0  1  1  1  1  1  0  1 
  1  1  1  1  0  1  1  0 

Open in new window

Such as:
Dim MyGroupByRow(8)  = 0 
For r = 1 to 8
    For c = 1 to 8  
        If RowCol(r,c) = 0   And   MyGroupByRow(r)  = 0  Then 
            ' 1st col found in row = 1 is c = 7.     r2 will be=2  r3=3, r4=4, r5=5, r6=1, r7=?
            MyGroupRow(r) = c
            Exit For   ' We're done with this row, exit this For c = loop and go to next r.
        End If
    Next
Next

Open in new window

The problem starts at r = 7 because I can't find a still available column which is 0 and not already taken in MyGroupRow().
You just can't the 1st column with a 0 in each row.  
How do I program some sort of deeper iteration code logic to find the right group?
Avatar of Shaun Vermaak
Shaun Vermaak
Flag of Australia image

Just a comment:

MyGroupByRow(8) is a base 0 array, so 0 to 7, not 1 to 8 as per the example code
Avatar of JReam

ASKER

Shawn, that (8) would be 9 elements in the array 0 to 8.  Just ignore the unused 0.  
This is irrelevant to the real question about how to find the groups.  Can you help with the question? Thanks.
ASKER CERTIFIED SOLUTION
Avatar of Robert Schutt
Robert Schutt
Flag of Netherlands image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Yup was typo

MyGroupByRow(8) is a base 0 array, so 0 to 8, not 1 to 8 as per the example code
Avatar of JReam

ASKER

Hey Robert  -

Thank you so much for your assistance with Recursion!    We were able to apply your logic to our bigger project quite successfully.   For me, I seem to have a brain block/freeze with recursion.    Your guidance greatly appreciated.  

You are the man!    I'd raise the points for this Q&A if I could.  

Thanks,
John