# include # include # include using namespace std; # include "polyomino_condense.hpp" int main ( ); void condense_demo ( int mp, int np, int p[] ); //****************************************************************************80 int main ( ) //****************************************************************************80 // // Purpose: // // MAIN is the main program for POLYOMINO_CONDENSE_TEST. // // Discussion: // // POLYOMINO_CONDENSE_TEST tests POLYOMINO_CONDENSE. // // Licensing: // // This code is distributed under the GNU LGPL license. // // Modified: // // 29 April 2018 // // Author: // // John Burkardt // // Local parameters: // // Local, int MP, NP, the number of rows and columns in the representation // of the polyomino P. // // Local, int P[MP*NP], a matrix representing the polyomino. // { int mp; int np; int p1[] = { 0, 1, 1, 1, 1, 0, 0, 1, 0 }; int p2[] = { 0, 1, 2, 1, 3, 0, 0, -9, 0 }; int p3[] = { 0, 0, 0, 0, 1, 3, 0, 0, 0, 0, 0, 0 }; int p4[] = { 0, 0, 0, 0, 0, 0, 0, 0 }; timestamp ( ); cout << "\n"; cout << "POLYOMINO_CONDENSE_TEST:\n"; cout << " C version\n"; cout << " POLYOMINO_CONDENSE 'cleans up' a matrix that is supposed\n"; cout << " to represent a polyomino:\n"; cout << " * nonzero entries are set to 1;\n"; cout << " * initial and final zero rows and columns are deleted.\n"; // // Nothing happens: // mp = 3; np = 3; condense_demo ( mp, np, p1 ); // // Nonzero, but non-one entries are set to 1. // mp = 3; np = 3; condense_demo ( mp, np, p2 ); // // Extraneous zero rows and columns are removed. // mp = 3; np = 4; condense_demo ( mp, np, p3 ); // // Null matrices are detected. // mp = 2; np = 4; condense_demo ( mp, np, p4 ); // // Terminate. // cout << "\n"; cout << "POLYOMINO_CONDENSE_TEST:\n"; cout << " Normal end of execution.\n"; cout << "\n"; timestamp ( ); return 0; } //****************************************************************************80 void condense_demo ( int mp, int np, int p[] ) //****************************************************************************80 // // Purpose: // // CONDENSE_DEMO demonstrates the result of calling POLYOMINO_CONDENSE. // // Licensing: // // This code is distributed under the GNU LGPL license. // // Modified: // // 29 April 2018 // // Author: // // John Burkardt // // Parameters: // // Input, int MP, NP, the number of rows and columns in the representation // of the polyomino P. // // Input, int P[MP*NP], a matrix representing the polyomino. // // Local, int MQ, NQ, the number of rows and columns in the representation // of the condensed polyomino Q. // // Local, int Q[MQ*NQ], a matrix representing the condensed polyomino. // { string label; int mq; int nq; int *q; label = " The initial (" + to_string ( mp ) + "," + to_string ( np ) + ") polynomino P:"; polyomino_print ( mp, np, p, label ); polyomino_condense ( mp, np, p, mq, nq, &q ); label = " The condensed (" + to_string ( mq ) + "," + to_string ( nq ) + ") polynomino Q:"; polyomino_print ( mq, nq, q, label ); if ( *q ) { delete [] q; } return; }