Пример #1
0
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);
  }
}
Пример #2
0
void partitionAllHelper(int budget, int *partition, int pos)
{

  //BASE CASE!!!
  if (budget == 0){
    printpartition(partition, pos);
    return;
  }
  

  //INDUCTIVE CASE!!!!!
  int spending;
  for(spending = 1; spending <= budget; spending+= 1){
    partition[pos] = spending;
    partitionAllHelper(budget - spending, partition, pos + 1);
  }
}
Пример #3
0
void partitionOddAndEvenHelper(int budget, int *partition, int pos)
{
  //BASE CASE!!!
  if (budget <= 0){
    printpartition(partition, pos);
    return;
  }  

  //INDUCTIVE CASE!!!!!
  int spending;
  for(spending = 1; spending <= budget ; spending += 1){ 
    partition[pos] = spending;
    if(pos ==  0 || Isodd(partition[pos - 1]) != Isodd(partition[pos])){
      // partition[pos] = spending;
      partitionOddAndEvenHelper(budget - spending, partition, pos + 1);
      }
  }
}
Пример #4
0
void partition_inc(int * arr, int index, int n)
{
  int test;

  if (n == 0)
    {
      printf("= ");
      printpartition(arr, index);
      return;
    }
  for (test = 1; test <= n; test++)
    {
      if ((index == 0) || (arr[index - 1] < test))
	{
	  arr[index] = test;
	  partition_inc(arr, index + 1, n - test);
	}
    }
}
Пример #5
0
void partition_all(int * arr, int index, int n)
{
  int test;

  if (n == 0)
    {
      printf("= ");
      printpartition(arr, index);
      return;
    }
  else
    {
      for (test = 1; test <= n; test++)
	{
	  arr[index] = test;
	  partition_all(arr, index + 1, n - test);
	}
    }
}
Пример #6
0
void partition_prime(int * arr, int index, int n)
{
  int test;
  int track = 0;

  if (n == 0)
    {
      printf("= ");
      printpartition(arr, index);
      return;
    }
  else
    {
      for (test = 1; test <= n; test++)
	{
	  track = check_prime(test);
	  if ((track <= 2) && (test != 1))
	    {
	      arr[index] = test;
	      partition_prime(arr, index + 1, n - test);
	    }
	}
    }
}