Пример #1
0
void partoe(int * part, int ind, int left, int oe)
{
  if(left==0)
    {
      printPartition(part,ind);
      return;
    }
  else if(left<0)
    {
      return;
    }
  int val;
  for(val=1;val<=left;val++)
    {
      if(oe==0 && val%2==0)
	{
	  part[ind]=val;
	  partoe(part,ind+1,left-val,1);
	}
      else if(oe==1 && val%2==1)
	{
	  part[ind]=val;
	  partoe(part,ind+1,left-val,0);
	}
    }
  return;
}
Пример #2
0
void partitionOddandEvenHelper(int N, int * partition, int pos)
{
	//BASE CASE
	if(N == 0)
	{
	printPartition(partition, pos);
	return;
	}
	//INDUCTIVE CASE
	int i;
	for(i = 1; i <= N; i++)	
{
	int val = 0;
	if(pos == 0)
	{
	val = 1;
	}
	else
	{
	val = (partition[pos - 1] % 2) != (i % 2);
	}
	if(val == 1)
	{
	partition[pos] = i;
	partitionOddandEvenHelper(N - i, partition, pos + 1);
	}
}
}
void printPartition(unsigned n, unsigned k)
{ if (1 == k)
    print(1, n);
  else {
    printPartition(b[n][k], k - 1);
    print(b[n][k] + 1, n);
  }
}
Пример #4
0
void partitionAll_helper(int* part, int ind, int left){
	int val;
	if(left == 0){
		printPartition(part, ind);
		return;
	}
	for(val = 1;val <= left;val++){
		part[ind] = val;
		partitionAll_helper(part, ind+1, left-val);
	}
}
Пример #5
0
void partitionOddEven(int * part, int ind, int left, int status)
{
  int val;
  if (left == 0)
    {
      printf("= ");
      printPartition(part, ind);
      return;
    }
  /*for (val = 1; val <= left; val++)
    {
      if ((ind == 0) || (((part[ind - 1] % 2) == 0) && ((val%2) == 1)))
	{
          part[ind] = val;
          partitionOddEven(part, ind + 1, left  - val);
	}
      else if((ind == 0) || ((part[ind - 1] % 2) == 1 && (val%2) == 0))
        {
            part[ind] = val;
            partitionOddEven(part, ind + 1, left  - val);
	}
    }*/
  else
    {
      if (status % 2 == 0)
	{
	  status++;
	  for(val = 1; val <= left; val = val + 2)
	    {
              part[ind] = val;
              partitionOddEven(part, ind + 1, left  - val, status);
	    }
	}
      else
	{
	  status++;
	  for(val = 2; val <= left; val = val + 2)
	    {
	      part[ind] = val;
	      partitionOddEven(part, ind + 1, left - val, status);
	    }
	}
    }




}    
Пример #6
0
void partitionOddHelper(int N, int *partition, int pos)
{
	//BASE CASE
	if(N == 0)
	{
	printPartition(partition, pos);
	return;
	}
	//INDUCTIVE CASE
	int i; 
	for(i = 1; i <= N; i+= 2)
	{
	partition[pos] = i;
	partitionOddHelper(N - i, partition, pos + 1);
	}
}
Пример #7
0
/*
 * =================================================================
 * This function prints alternate ood and even number partitions of a positive integer value. Each partition starts from and odd number, even number, ood number again, even number again...etc.
 *
 * For example, if value is 6
 * 1 + 2 + 1 + 2 and
 * 3 + 2 + 1 are valid partitions
 *
 * 6 is not a valid partition
 *
 * 2 + 1 + 1 + 2 and
 * 2 + 1 + 3and
 * 5 + 1 are invalid partitions.
 * 
 * The program should generate only valid partitions.  Do not
 * generates invalid partitions and checks validity before printing.
 */
void partitionOddandEvenHelper(int * part, int ind, int left)
{
  int val;
  if (left == 0)
    {
      printPartition(part, ind);
      return;
    }
  for (val = 1; val <= left; val ++)
    {
      if((val%2 ==1 && ind%2==0)  ||  ((val%2==0 && ind%2==1)))
	{
	  part[ind] = val;
	  partitionOddandEvenHelper(part, ind + 1, left - val);
	}
    }
}
Пример #8
0
/*
 * =================================================================
 * This function prints even number only partitions of a positive integer value
 * For example, if value is 8
 * 2 + 2 + 2 + 2and
 * 2 + 4 + 2 are valid partitions
 *
 * 8 is a valid partition
 *
 * 2 + 1 + 1 + 2 + 2and
 * 2 + 1 + 2 + 3and
 * 5 + 3 are invalid partitions.
 *
 * if the value is 5, there will be no result generated
 * 
 * The program should generate only valid partitions.  Do not
 * generates invalid partitions and checks validity before printing.
 */
void partitionevenhelp(int * part, int ind, int left)
{
  int val;
  if (left == 0)
    {
      printPartition(part, ind);
      return;
    }
  for (val = 1; val <= left; val ++)
    {
      if((val%2)==0)
	{
	  part[ind] = val;
	  partitionevenhelp(part, ind + 1, left - val);
	}
    }
  }
Пример #9
0
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);
	}
}
Пример #10
0
void partitionPrimeCalc(int * part, int ind, int left)
{
  int val;
  if (left == 0)
    {
      printf("= ");
      printPartition(part, ind);
      return;
    }
  for (val = 1; val <= left; val++)
    {
      if (isPrime(val) < 3 && (val!= 1))
	{
          part[ind] = val;
          partitionPrimeCalc(part, ind + 1, left  - val);
	}
    }
}    
Пример #11
0
void partitionIncreasingHelper(int N, int * partition, int pos)
{
	//BASE CASE
	if(N == 0)
	{printPartition(partition, pos);
	return;
	}

	//INDUCTIVE CASE
	int i;
	int start = pos == 0 ? 1 : partition[pos - 1] + 1;
	for(i = start; i <= N; i++)
	{
	partition[pos] = i;
	partitionIncreasingHelper(N - i, partition, pos + 1);
	}
		
}
Пример #12
0
void partitionDecreasingHelper(int N, int * partition, int pos)
{
	//BASE CASE
	if(N == 0)
	{
	printPartition(partition, pos);
	return;
	}

	//INDUCTIVE CASE
	int i;
	int start = pos == 0 ? N : partition[pos - 1] - 1;
	for(i = start; i > 0; i--)
	{
	partition[pos] = i;
	partitionDecreasingHelper(N - i, partition, pos + 1);
	}
}
Пример #13
0
void partitionInc(int * part, int ind, int left)
{
  int val;
  if (left == 0)
    {
      printf("= ");
      printPartition(part, ind);
      return;
    }
  for (val = 1; val <= left; val++)
    {
      if ((ind == 0) || part[ind - 1] < val)
	{
          part[ind] = val;
          partitionInc(part, ind + 1, left  - val);
	}
    }
}    
Пример #14
0
void partitionOddNum(int * part, int ind, int left)
{
  int val;
  if (left == 0)
    {
      printf("= ");
      printPartition(part, ind);
      return;
    }
  for (val = 1; val <= left; val++)
    {
      if ((val % 2) == 1)
	{
          part[ind] = val;
          partitionOddNum(part, ind + 1, left  - val);
	}
    }
}    
Пример #15
0
void partdec(int * part, int ind, int left, int nxt)
{
  if(left==0)
    {
      printPartition(part,ind);
      return;
    }
  else if(left<0)
    {
      return;
    }
  int val;
  for(val=nxt;val>0;val--)
    {
      part[ind]=val;
      partdec(part,ind+1,left-val,val-1);
    }
  return;
}
Пример #16
0
void partitionPrime_helper(int* part, int ind, int left){
	int val;
	if(left == 0){
		printPartition(part, ind);
		return;
	}
	for(val = 1;val <= left;val++){
		if(ind == 0 && isPrime(val)){
			part[ind] = val;
			partitionPrime_helper(part, ind+1, left-val);
		}
		else{
			if(isPrime(val)){
				part[ind] = val; 
				partitionPrime_helper(part, ind+1, left-val);
			}
		}
	}
}
Пример #17
0
void partitionOddAndEven_helper(int* part, int ind, int left){
	int val;
	if(left == 0){
		printPartition(part, ind);
		return;
	}
	for(val = 1;val <= left;val++){
		if(ind == 0 && val % 2 > 0){
			part[ind] = val;
			partitionOddAndEven_helper(part, ind+1, left-val);
		}
		else{
			if( (val % 2 == 0 && part[ind-1] % 2 > 0) || (val % 2 > 0 && part[ind-1] % 2 == 0) ){
				part[ind] = val; 
				partitionOddAndEven_helper(part, ind+1, left-val);
			}
		}
	}
}
Пример #18
0
void partitionIncreasing_helper(int* part, int ind, int left){
	int val;
	if(left == 0){
		printPartition(part, ind);
		return;
	}
	for(val = 1;val <= left;val++){
		if(ind == 0){
			part[ind] = val;
			partitionIncreasing_helper(part, ind+1, left-val);
		}
		else{
			if(val > part[ind-1]){
				part[ind] = val;
				partitionIncreasing_helper(part, ind+1, left-val);
			}
		}
	}
}
Пример #19
0
void partinc(int * part, int ind, int left, int nxt)
{
  int val;
  if(left==0)
    {
      printPartition(part, ind);
      return;
    }
  else if(left<0)
    {
      return;
    }
  for(val=nxt;val<=left;val++)
    {
      part[ind]=val;
      partinc(part,ind+1,left-val,val+1);
    }
  return;
}
Пример #20
0
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);
	}
    }
  
}
Пример #21
0
void partodd(int * part, int ind, int left)
{
  if(left==0)
    {
      printPartition(part,ind);
      return;
    }
  else if(left<0)
    {
      return;
    }
  int val;
  for(val=1;val<=left;val++)
    {
      if(val%2==1)
	{
	  part[ind]=val;
	  partodd(part,ind+1,left-val);
	}
    }
  return;
}
Пример #22
0
void partprime(int * part, int ind, int left)
{
  if(left==0)
    {
      printPartition(part,ind);
      return;
    }
  else if(left<0)
    {
      return;
    }
  int val;
  for(val=2;val<=left;val++)
    {
      if(isprime(val)==1)
	{
	  part[ind]=val;
	  partprime(part,ind+1,left-val);
	}
    }
  return;
}
int main(void) {
  printf("\nМаксимална сума в някоя от групите: %lu", doPartition(k));
  printPartition(n, k);
  return 0;
}
Пример #24
0
/*------------------------------------------------------------------------------
* Name:  main
* Action:  Print out partition tables.
*-----------------------------------------------------------------------------*/
int main ()
{
  int           rc;                       /* Return code        */
  int           fd;                       /* Device descriptor  */           
  int           sector;   		          /* IN: sector to read */
  unsigned char buf[SECTOR_SZ];	          /* temporary buffer   */

  struct partition partitions[32];
  int count;
  int jump;
  int start = 446;
  int totalcount;

  /* Open the device */
  fd = open ( "disk", O_RDWR ); 
  if ( fd == -1 ) 
  {
    perror ( "Could not open device file" );
    exit(-1);
  }

  /* Read the sector */
  sector = atoi( "0" );
  rc = readSectors ( fd, sector, 1, buf );
  if ( rc == -1 )
  {
    perror ( "Could not read sector" );
    exit(-1);
  }

  /* Read the first 4 partitions in MBR and print them */
  for(count = 0; count < 4; count++)
  {
    jump = readPartition(1, start + count*16, buf, partitions, count, 0);
	printPartition(partitions, count);
  }

  /* Update total count of entries in array */
  totalcount = count;

  /* Traverse extended partitions, printing out entries, until we hit an empty entry */
  while (jump > 0)
  {
    /* Read the sector */
    sector = jump;
    rc = readSectors ( fd, sector, 1, buf );
    if ( rc == -1 )
    {
      perror ( "Could not read sector" );
      exit(-1);
    }

  /* Reset count and jump information */
    count = 0;
    jump = 1;

  /* Traverse sector, printing each entry, until we hit either an empty or extended entry */
    while (jump == 1)
    {
      jump = readPartition(0, start + count*16, buf, partitions, totalcount, sector);
      if (jump == 1)
      {
		printPartition(partitions, totalcount);

        count = count + 1;
        totalcount = totalcount + 1;
      }
    }
  }

  close(fd);
  return 0;
}