void partOddAndEven(int value, int * arr, int ind) { int n = 0; if (value == 0) { printpart(arr, ind); return; } for (n = 1; n <= value; n++) { arr[ind] = n; if (ind == 0 && ((arr[0] % 2) != 0)) { partOddAndEven(value - n, arr, ind + 1); } else if ( (((arr[ind] + arr[ind - 1]) % 2) != 0) && ((arr[0] % 2) != 0)) { arr[ind] = n; partOddAndEven(value - n, arr, ind + 1); } } }
void part(int value, int * arr, int ind) { int n = 0; if (value == 0) { printpart(arr,ind); return; } for (n = 1; n <= value; n++) { arr[ind] = n; part(value-n, arr, ind + 1); } }
int main(int argc, char **argv) { int i,stillhappy; Display *display; int events; srand48(874984); frame=0; /* Connect to the server for display */ display = BWConnectToServer(); /* Open the windows */ window1 = BWCreateNewWindow(display, argc, argv); for (i=0; i<numps; i++) { randpart(&particle[i]); printpart(&particle[i]); nl(); } while(1) { events = BWCheckEvents(window1); switch (events) { /* Window exposed - redraw */ case EV_EXPOSED: { plotparts(); break; } /* Mouse button pressed - close both windows and exit*/ case EV_BUTTON: { BWCloseWindow(window1); exit(0); } default: { plotparts(); moveparts(); frame++; break; } } } }
void partPrime(int value, int* arr, int ind) { int n = 0; int primenum = 0; int prime(int n); if (value == 0) { printpart(arr, ind); return; } for (n = 1; n <= value; n++) { primenum = prime(n); if (primenum == 1) { arr[ind] = n; partPrime(value - n, arr, ind + 1); } } }
void partDec(int value, int * arr, int ind) { int n = 0; if (value == 0) { printpart(arr, ind); return; } for (n = 1; n <= value; n++) { arr[ind] = n; if (ind == 0) { partDec(value - n, arr, ind + 1); } else if ( arr[ind] < arr[ind - 1]) { arr[ind] = n; partDec(value - n, arr, ind + 1); } } }
void partInc(int value, int * arr, int ind) { int n = 0; if (value == 0) { printpart(arr, ind); return; } for (n = 1; n <= value; n++) { arr[ind] = n; //if (ind == 0) //{ // partInc(value - n, arr, ind + 1); //} if ( arr[ind] > arr[ind - 1]) { arr[ind] = n; partInc(value - n, arr, ind + 1); } } }