# include # include # include # include "polyomino_index.h" /******************************************************************************/ int *polyomino_index ( int m, int n, int p[] ) /******************************************************************************/ /* Purpose: POLYOMINO_INDEX assigns an index to each nonzero entry of a polyomino. Discussion: The indexing scheme arbitrarily proceeds by rows. Example: P = 1 0 1 1 1 1 1 0 0 1 1 0 PIN = 1 0 2 3 4 5 6 0 0 7 8 0 Licensing: This code is distributed under the GNU LGPL license. Modified: 17 May 2018 Author: John Burkardt Parameters: Input, int M, N, the number of rows and columns in the array that represents the polyomino. Input, int P[M*N], the polyomino. It is assumed that every entry is a 0 or a 1. Output, int *PIN[M*N], the index of each nonzero entry. */ { int i; int j; int k; int *pin; pin = ( int * ) malloc ( m * n * sizeof ( int ) ); k = 0; for ( i = 0; i < m; i++ ) { for ( j = 0; j < n; j++ ) { if ( p[i+j*m] != 0 ) { k = k + 1; pin[i+j*m] = k; } else { pin[i+j*m] = 0; } } } return pin; } /******************************************************************************/ void polyomino_print ( int m, int n, int p[], char *label ) /******************************************************************************/ /* Purpose: POLYOMINO_PRINT prints a polyomino. Licensing: This code is distributed under the GNU LGPL license. Modified: 29 April 2018 Author: John Burkardt Parameters: Input, int M, N, the number of rows and columns in the representation of the polyomino P. Input, int P[M*N], a matrix of 0's and 1's representing the polyomino. Input, char *LABEL, a title for the polyomino. */ { int i; int j; printf ( "\n" ); printf ( "%s\n", label ); printf ( "\n" ); if ( m <= 0 || n <= 0 ) { printf ( " [ NULL matrix ]" ); } else { for ( i = 0; i < m; i++ ) { for ( j = 0; j < n; j++ ) { printf ( " %d", p[i+j*m] ); } printf ( "\n" ); } } 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 GNU LGPL 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 }