0
\$\begingroup\$

I have this data

enter image description here

As you can see there's a 2nd board there.

Now what i want is something like this

PSEUDO CODE

If the first boards table[1,1] is not `NULL` then I will need to find out 
now if table[0,1] and table[0,0] has the same length as table[1,1] and 
table[1,0]

then display in the 2nd board a blue circle if it is the same in length if 
not red circle

But if the table[1,1] is `NULL` then I need to know compare 1st column and 
2nd column if they have the same length

then display in the 2nd board a blue circle if it is the same in length if 
not red circle

END PSEUDO CODE

I tried doing the following

//COLUMN
    for(int col = 0; col < table.GetLength(0); col++)
    {
        int sum = 0;
        //ROW
        for (int row = 0; row < table.GetLength(1); row++)
        {
            if (table[col, row] != null)
            {
                Debug.Log("Column 1 has this value : " + table[col, row]);
            } 
        }
        //Debug.Log("table column: " + col + " has " + sum + " data");
    }

For now I can only get the whole Row and Column but I don't know how to do that pseudo code.

\$\endgroup\$

1 Answer 1

0
\$\begingroup\$
//COLUMN
int prevSum = -1;
for (int col = 0; col < table.GetLength(0); ++col)
{

int sum = CountRow(table, col);
Debug.Log("table column :" + col + " has " + sum + " data");
if (sum == prevSum)
{
   prevSum = sum;
}

//generic function
public static int CountRow<T>(T[,] table, int col)
{
    if (table == null || col < 0 || col >= table.GetLength(1)) 
    {
        //handle error
        return -1;
    }

    //this is the same as the block of the outer for loop
    int sum = 0;
    for (int row = 0; row < table.GetLength(1); row++)
    {
        if(table[col,row] != null)
        {
            sum++;
        }
    }
    return sum;
}
\$\endgroup\$

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.