# include # include # include # include # include "pentominoes.h" int main ( ); void pentomino_matrix_test ( ); void pentomino_plot_test ( ); void timestamp ( ); /******************************************************************************/ int main ( ) /******************************************************************************/ /* Purpose: pentominoes_test() tests pentominoes(). Licensing: This code is distributed under the MIT license. Modified: 21 April 2018 Author: John Burkardt */ { timestamp ( ); printf ( "\n" ); printf ( "PENTOMINOES_TEST\n" ); printf ( " C version\n" ); printf ( " Test the PENTOMINOES library.\n" ); pentomino_matrix_test ( ); pentomino_plot_test ( ); /* Terminate. */ printf ( "\n" ); printf ( "PENTOMINOES_TEST\n" ); printf ( " Normal end of execution.\n" ); printf ( "\n" ); timestamp ( ); return 0; } /******************************************************************************/ void pentomino_matrix_test ( ) /******************************************************************************/ /* Purpose: PENTOMINO_MATRIX_TEST tests PENTOMINO_MATRIX. Licensing: This code is distributed under the MIT license. Modified: 21 April 2018 Author: John Burkardt */ { int i; int j; int k; char name; int *p; int p_m; int p_n; char pentominoes[12] = { 'F', 'I', 'L', 'N', 'P', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z' }; printf ( "\n" ); printf ( "PENTOMINO_MATRIX_TEST\n" ); printf ( " PENTOMINO_MATRIX returns a 0/1 matrix representing a pentomino.\n" ); for ( k = 0; k < 12; k++ ) { name = pentominoes[k]; pentomino_matrix ( name, &p_m, &p_n, &p ); printf ( "\n" ); printf ( " %c pentomino (%d,%d):\n", name, p_m, p_n ); printf ( "\n" ); for ( i = 0; i < p_m; i++ ) { printf ( " " ); for ( j = 0; j < p_n; j++ ) { printf ( "%d", p[i*p_n+j] ); } printf ( "\n" ); } free ( p ); } return; } /******************************************************************************/ void pentomino_plot_test ( ) /******************************************************************************/ /* Purpose: PENTOMINO_PLOT_TEST tests PENTOMINO_PLOT. Licensing: This code is distributed under the MIT license. Modified: 21 April 2018 Author: John Burkardt */ { int k; char label[2]; char name; int *p; int p_m; int p_n; char pentominoes[12] = { 'F', 'I', 'L', 'N', 'P', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z' }; printf ( "\n" ); printf ( "PENTOMINO_PLOT_TEST\n" ); printf ( " PENTOMINO_PLOT plots a pentomino.\n" ); for ( k = 0; k < 12; k++ ) { name = pentominoes[k]; sprintf ( label, "%c", name ); pentomino_matrix ( name, &p_m, &p_n, &p ); pentomino_plot ( p_m, p_n, p, label ); } return; } /******************************************************************************/ void timestamp ( ) /******************************************************************************/ /* Purpose: TIMESTAMP prints the current YMDHMS date as a time stamp. Example: 17 June 2014 09:45:54 AM Licensing: This code is distributed under the MIT license. Modified: 17 June 2014 Author: John Burkardt Parameters: None */ { # define TIME_SIZE 40 static char time_buffer[TIME_SIZE]; const struct tm *tm; time_t now; now = time ( NULL ); tm = localtime ( &now ); strftime ( time_buffer, TIME_SIZE, "%d %B %Y %I:%M:%S %p", tm ); printf ( "%s\n", time_buffer ); return; # undef TIME_SIZE }