Mathfinder - This program finds (r1 r2 ...)-graceful sequences of length n, for n>3 and ri>2. A graceful sequence is defined as a permutation of the numbers 1..n such that the difference between any two adjacent elements is unique, and so a list of the differences between adjacent elements is a permutation of the numbers 1..n-1. A r-graceful sequence (g) is defined as a graceful sequence, where s is a sequence of partial sums such that s1 = r1 and s2 = r1+r2, all the way up to sk = r1+r2+...+rk, and the following additional properties hold: g(s1)-g(1) = g(s1+1)-g(s1) g(s2)-g(s1+1) = g(s2+1)-g(s2) g(s3)-g(s2+1) = g(s3+1)-g(s3) ... g(sk)-g(s(k-1)+1) = g(sk+1)-g(sk) * Mathfinder searches for lists with these properties by recursively adding elements to a list, and at each step checking the list for some of these properties, then checking for the other properties once a complete list has been found. * - From _Finding Sequences with Useful Properties_, by M A Ollis (2006) Documentation: USAGE: mathfind [-t] [n] [r1 r2 ...] [-t]: Runs tests instead of normal operation. Requires , but not [n] or [r1 r2 ...]. The file mathfind.garbage is used as scratch. : A file where the output will be written. The data is appended to the file. [n]: The value of n. Must be at least 4. [r1 r2 ...]: The values of r, delimited by spaces. Each value must be at least 3, but the sum of all of them must be less than n.\n Examples: mathfind try.txt 11 4 5 Prints the results for n=11 and r=(4 5) to try.txt mathfind -t test.log Tests the program and stores the results in test.log Version History: Since 4.1.4: - The code has been reformatted for viewing on emacs or other 80 column viewers. - The only operative change is the breaking of print statements. Since 4.1.3: - The program now checks the inputs for validity before running. - Error reporting has been improved. Since 4.1.2: - Some minor changes for greater unix compatability. - The time recording/reporting has been switched to wall time, as clock() does not do what I want on CS. Since 4.1.1: - Code comments are now complete and up to date. Since 4.1.0: - The program now has a testing mode when invoked with the -t switch. - That switch runs several tests and reports/records the results. - The usage has been updated. Since 4.0.3: - The program now detects some forms of bad input and prints the usage instructions. Since 4.0.2: - The program now uses the ANSI standard flockfile method to synchronize output. - Seeking has been implemented to prevent data overwriting during output. Since 4.0.1: - The program now uses the GNU fcntl library as a semaphore to synchronize output. Since 4.0.0: - The code now implements multiple forks to divide the searching into multiple simultaneous processes, with the parent finalizing. Since 3.6.0: - RC0: No extra checking. - RC1: This version checks an extra property of graceful labellings, as the first check for each possible new number. - RC2: This version checks an extra property of graceful labellings, as the second check for each possible new number. - RC3: This version checks an extra property of graceful labellings, as the third check for each possible new number. - RC4: This version checks an extra property of graceful labellings, as the fourth check for each possible new number. - The final version is RC4. Since 3.5.0: - RC0: This version uses fixed array sizes, and local variables. - RC1: This version uses malloc to allocate memory and manually initializes it, and uses local variables. - RC2: This version uses calloc to allocate memory, and uses local variables. - RC3: This version uses fixed array sizes and global variables. - RC4: This version uses malloc to allocate memory and manually initializes it, and uses global variables. - RC5: This version uses calloc to allocate memory, and uses global variables. - The final version is RC1. Since 3.4.1: - The program now outputs both the detected solution and its complement to the log file, although it only displays the detected one. Since 3.4.0: - RC0: No extra checking. - RC1: The program now checks possible next elements against the first element of s, before the other checks. - RC2: The program now checks possible next elements against the first element of s, after the other checks. - All versions now include speed reporting to the screen and the text log. - The final version is RC2. Since 3.3.0: - The program now outputs to a file as well as to the screen. - The backTrack routine is now more efficient. - The program now complies with the ANSI C specification. Since 3.2.2: - Fixed an error in the test routine to examine for all of the elements of |s|, rather than just the first 2. - Fixed an error in the recurse routine that was discarding some valid possibilities. Since 3.2.1: - The program now only searches through the first half of all possibilities, relying on symmetry to detect solutions. Since 3.2.0: - The program now accepts input from the command line, with n<25 and |r|<=5. Since 3.1.1: - The maximum on the list length has been increased to 25, and some of the constructions have been unfixed. Since 3.1.0: - The program now reads a puzzle and an answer from two text files specified as arguments. - The program displays blanks as buttons. - The program can check the puzzle against the answer for correctness. Since 3.0.1: - This version does not compile. - The program displays a window with file and help menus. - The file menu contains a working quit button. - The help menu contains version and about windows that open descriptive dialog boxes. API: void main(int argc, char* argv[]) The main subroutine processes the arguments, opening and closing of the log files, calls pSums, and calls backTrack. void backTrack(FILE* file, int n, int size, int r[], int s[]) The backTrack subroutine splits the problem and creates a child process to handle each piece, then preps each run and calls recurse. s is a list of partial sums of r, size is the size of r and s, and file, n, and r are the output file, the list length, and the array specified in the arguments, repectively. void recurse(FILE* file, int n, int size, int r[], int s[], int used[], int h[], int list[], int count) The recursive portion of the program, each iteration looks for the next number it can add to the list. Variables are as above, with used identifying which numbers have been used already, h being which differences already exist, list being the list so far, and count being the element of list to fill next. int test (int size, int list[], int s[]) Once a list is completed, test checks it to make sure it holds with all requirements not guaranteed during creation. void pSums(int size, int r[], int s[]) Places a list of partial sums of the first size elements of r[] into s[]. void printMan(void) Prints the usage information. void programTest (FILE* file) Runs tests on the various routines of the program, storing the results in file.