# include # include # include # include # include "combination_lock.h" int main ( ); void combination_lock_test ( ); /******************************************************************************/ int main ( ) /******************************************************************************/ /* Purpose: MAIN is the main program for COMBINATION_LOCK_TEST. Discussion: COMBINATION_LOCK_TEST tests the COMBINATION_LOCK library. Licensing: This code is distributed under the GNU LGPL license. Modified: 13 May 2012 Author: John Burkardt */ { int c[4] = { 1, 2, 3, 4 }; int m = 4; int n = 5; int step; timestamp ( ); printf ( "\n" ); printf ( "COMBINATION_LOCK_TEST\n" ); printf ( " C version\n" ); printf ( " Test the COMBINATION_LOCK libary.\n" ); printf ( " A combination lock consists of M dials,\n" ); printf ( " each having N symbols.\n" ); printf ( " We seek to determine the combination C.\n" ); /* Report on the problem data. */ printf ( "\n" ); printf ( " The number of dials is M = %d\n", m ); printf ( " The number of symbols is N = %d\n", n ); printf ( " The number of possible combinations is M^N = %d\n", i4_power ( n, m ) ); i4vec_print ( m, c, " The \"secret\" combination:" ); step = combination_lock ( m, n, c ); if ( step == -1 ) { printf ( "\n" ); printf ( " The combination was not found!\n" ); } else { printf ( "\n" ); printf ( " The combination was found on step %d\n", step ); } /* Terminate. */ printf ( "\n" ); printf ( "COMBINATION_LOCK_TEST\n" ); printf ( " Normal end of execution.\n" ); printf ( "\n" ); timestamp ( ); return 0; }