# include # include # include using namespace std; # include "polyomino_embed.hpp" int main ( ); void polyomino_embed_list_test ( ); void polyomino_embed_number_test ( ); //****************************************************************************80 int main ( ) //****************************************************************************80 // // Purpose: // // MAIN is the main program for POLYOMINO_EMBED_TEST. // // Discussion: // // POLYOMINO_EMBED_TEST tests POLYOMINO_EMBED. // // Licensing: // // This code is distributed under the GNU LGPL license. // // Modified: // // 02 May 2018 // // Author: // // John Burkardt // { timestamp ( ); cout << "\n"; cout << "POLYOMINO_EMBED_TEST:\n"; cout << " C++ version\n"; cout << " Test the POLYOMINO_EMBED library.\n"; polyomino_embed_number_test ( ); polyomino_embed_list_test ( ); // // Terminate. // cout << "\n"; cout << "POLYOMINO_EMBED_TEST:\n"; cout << " Normal end of execution.\n"; cout << "\n"; timestamp ( ); return 0; } //****************************************************************************80 void polyomino_embed_list_test ( ) //****************************************************************************80 // // Purpose: // // POLYOMINO_EMBED_LIST_TEST tests POLYOMINO_EMBED_LIST. // // Licensing: // // This code is distributed under the GNU LGPL license. // // Modified: // // 02 May 2018 // // Author: // // John Burkardt // { int i; int j; int k; int *list; int mk; int nk; int mp = 3; int mq; int mr = 4; int np = 2; int nq; int nr = 4; int number; int p[3*2] = { 0, 0, 1, 1, 1, 1 }; int q[4*4]; int r[4*4] = { 0, 1, 1, 1, 1, 1, 1, 0, 1, 0, 1, 1, 1, 1, 1, 1 }; cout << "\n"; cout << "POLYOMINO_EMBED_LIST_TEST:\n"; cout << " POLYOMINO_EMBED_LIST lists the offsets used\n"; cout << " to embed a fixed polyomino in a region.\n"; polyomino_print ( mr, nr, r, " The given region R:" ); polyomino_print ( mp, np, p, " The given polyomino P:" ); // // Get the number of embeddings. // number = polyomino_embed_number ( mr, nr, r, mp, np, p ); cout << "\n"; cout << " As a fixed polyomino, P can be embedded in R in " << number << " ways\n"; /* Get the list of embeddings. */ list = polyomino_embed_list ( mr, nr, r, mp, np, p, number ); for ( k = 0; k < number; k++ ) { mk = list[k+0*number]; nk = list[k+1*number]; mq = mr; nq = nr; for ( j = 0; j < nq; j++ ) { for ( i = 0; i < mq; i++ ) { q[i+j*mq] = r[i+j*mr]; } } for ( j = 0; j < np; j++ ) { for ( i = 0; i < mp; i++ ) { q[i+mk+(j+nk)*mq] = q[i+mk+(j+nk)*mq] + p[i+j*mp]; } } cout << "\n"; cout << " Embedding number " << k << ":\n"; cout << "\n"; for ( i = 0; i < mq; i++ ) { for ( j = 0; j < nq; j++ ) { cout << " " << q[i+j*mq]; } cout << "\n"; } } delete [] list; return; } //****************************************************************************80 void polyomino_embed_number_test ( ) //****************************************************************************80 // // Purpose: // // POLYOMINO_EMBED_NUMBER_TEST tests POLYOMINO_EMBED_NUMBER. // // Licensing: // // This code is distributed under the GNU LGPL license. // // Modified: // // 02 May 2018 // // Author: // // John Burkardt // { int mp = 3; int mr = 4; int np = 2; int nr = 4; int number; int p[3*2] = { 0, 0, 1, 1, 1, 1 }; int r[4*4] = { 0, 1, 1, 1, 1, 1, 1, 0, 1, 0, 1, 1, 1, 1, 1, 1 }; cout << "\n"; cout << "POLYOMINO_EMBED_NUMBER_TEST:\n"; cout << " POLYOMINO_EMBED_NUMBER reports the number of ways a\n"; cout << " fixed polyomino can be embedded in a region.\n"; polyomino_print ( mr, nr, r, " The given region R:" ); polyomino_print ( mp, np, p, " The given polyomino P:" ); number = polyomino_embed_number ( mr, nr, r, mp, np, p ); cout << "\n"; cout << " As a fixed polyomino, P can be embedded in R in " << number << " ways\n"; return; }