// Ambrose Sterr // 04/05/06 // Version 3.0.1 // Doesn't compile. #include #include void backTrack(int, int*); void recurse(int, int*, int*, int*, int*, int); int test (int*, int*); void pSums(int, int*, int*); int main(void) { int n = 11; // Some default variables int size = 2; int r[2] = {4, 5}; int s[2]; pSums(size, r, s); // To calculate a list of partial sums if (s[1] == 9) // Just a test { printf("ok.\n"); } backTrack(n, s); // Gets the program going return 0; } void backTrack(int n, int s[]) { int used[9]; // Setup and intialization of the arrays to keep track of the numbers used and their differences. int h[11]; // The difference array. int i; // The iteration of first numbers. for (i = 1; i < 10; i++) { int j; int count = 1; for (j = 0; j < 9; j++) { used[j] = 0; } for (j = 0; j < n; j++) { h[j] = 0; } used[i]++; // The first number is used. int list[11]; // This is where the program blows apart, with "Missing '}'" list[0] = i; recurse(n, s, used, h, list, count); // This starts recursive scanning of the rest of the list. } } void recurse(int n, int s[], int used[], int h[], int list[], int count) { if (count != n) // If the list isn't filled in... { int i; for (i = 1; i <= n; i++) // Look for the next number to add... { if ((used[i] == 0)&&(h[abs(list[count-1]-i)]==0)) // ...make sure it's a good one... { list[count] = i; used[i]++; h[abs(list[count-1]-i)]++; recurse(n, s, used, h, list, count+1); // ...then head deeper in. h[abs(list[count-1]-i)]--; used[i]--; } } } else // But if it is... { if (test(list, s) == 1) // Check the list { printf("We got one!\n"); // Report a find! } } return 0; } int test (int list[], int s[]) // Checks for the extra property { if (abs(list[s[0]]-list[0])==abs(list[s[0]+1]-list[s[0]])) { if (abs(list[s[1]]-list[s[0]+1])==abs(list[s[1]+1]-list[s[1]])) { return 1; // Returns 1 if it is what I'm looking for } } return 0; // And 0 if it's not. } void pSums(int size, int r[], int s[]) // Makes a partial sum list out of the passed list. { int i; s[0] = r[0]; for (i = 1; i < size; i++) { s[i] = s[i-1] + r[i]; }; }