void partitionPrime(int value) { int *partition = malloc(sizeof(int) * value); partitionPrimeHelper(value, partition, 0); free(partition); }
void partitionPrime(int value) { printf("partitionPrime %d\n", value); int n=value; if (n <= 0) { return; } int * arr; arr = malloc(sizeof(int) * n); partitionPrimeHelper(arr, 0, n); free (arr); return; }
void partitionPrimeHelper(int budget, int *partition, int pos) { //BASE CASE!!! if (budget == 0){ printpartition(partition, pos); return; } //INDUCTIVE CASE!!!!! int spending; for(spending = 2; spending <= budget ; spending++){ if(!Isprime(spending)) continue; partition[pos] = spending; partitionPrimeHelper(budget - spending, partition, pos + 1); } }
void partitionPrimeHelper(int N, int *partition, int pos) { //BASE CASE if(N == 0) { printPartition(partition, pos); return; } //INDUCTIVE CASE int i; for(i = 2; i <= N; i++) { if(!isPrime(i)) continue; partition[pos] = i; partitionPrimeHelper(N - i, partition, pos + 1); } }
void partitionPrimeHelper(int * part, int ind, int left) { int val; int primetest; if (left == 0) { printPartition(part, ind); return; } for (val = 1; val <= left; val ++) { primetest = testPrime(val); if(primetest==1&& val!=1) { part[ind] = val; partitionPrimeHelper(part, ind + 1, left - val); } } }