Search code examples
c#arraystruthtable

Change columns orders in Multidimensional Array


Im building a Truth Table Generator, and to be able to get all the possible values for each column i started with the first one(False, True, False, True, etc.), then the next(false, false, true, true, etc.).

Now my table looks like this:

False |False |False |False |

True |False |False |False |

False |True |False |False |

True |True |False |False |

False |False |True |False |

True |False |True |False |

False |True |True |False |

True |True |True |False |

False |False |False |True |

True |False |False |True |

False |True |False |True |

True |True |False |True |

False |False |True |True |

True |False |True |True |

False |True |True |True |

True |True |True |True |

And i want the columns to go in the opposite way, the one on the right, the first, and the one on the left, the last. I know how to swap 2 columns, but what is the best algorithm to change the order? Should i work with this order, and then, when printing, just do it backwards?

Note: the number of columns depends on the number of variables, so it changes on each execution.


Solution

  • I could not find any easy way for ordering the columns, but if theres anyone else with the same problem, i made this:

    for (int i = 0; i < numrows; i++)
    {
                    for (int j = 0; j < numcolum; j++)
                    {
                        newtable[i, j] = table[i, numcolum- 1 - j];
                    }
    }
    

    Copy to another one backwards and done. I'm not really sure if theres a better way, or more efficient way to solve this problem.