Beispiel #1
0
int intPow(int x, int p)
{
  if (p == 0) return 1;
  if (p == 1) return x;

  int tmp = intPow(x, p/2);
  if (p%2 == 0) return tmp * tmp;
  else return x * tmp * tmp;
}
Beispiel #2
0
int main(){
	int base, exp;

	printf("Base: ");
	scanf("%d", &base);
	printf("Exp: ");
	scanf("%d", &exp);

	printf("\nPow = %d\n", intPow(base, exp));

	return 0;
}
Beispiel #3
0
int intPow(int x, int y){
	int res;

	if (y == 1){
		return x;
	}

	res = intPow(x, y / 2);

	if (y % 2){
		return res * res * x;
	}
	
	return res * res;
}
Beispiel #4
0
int xl_col_name_to_value(const QString &col_str)
{
    QRegularExpression re(QStringLiteral("^([A-Z]{1,3})$"));
    QRegularExpressionMatch match = re.match(col_str);
    if (match.hasMatch()) {
        int col = 0;
        int expn = 0;
        for (int i=col_str.size()-1; i>-1; --i) {
            col += (col_str[i].unicode() - 'A' + 1) * intPow(26, expn);
            expn++;
        }

        return col;
    }
    return -1;
}
Beispiel #5
0
QPoint xl_cell_to_rowcol(const QString &cell_str)
{
    if (cell_str.isEmpty())
        return QPoint(-1, -1);
    QRegularExpression re(QStringLiteral("^([A-Z]{1,3})(\\d+)$"));
    QRegularExpressionMatch match = re.match(cell_str);
    if (match.hasMatch()) {
        QString col_str = match.captured(1);
        QString row_str = match.captured(2);
        int col = 0;
        int expn = 0;
        for (int i=col_str.size()-1; i>-1; --i) {
            col += (col_str[i].unicode() - 'A' + 1) * intPow(26, expn);
            expn++;
        }

        int row = row_str.toInt();
        return QPoint(row, col);
    } else {
        return QPoint(-1, -1); //...
    }
}
Beispiel #6
0
int main(int argc, char *argv[]){
	int m[101];
	my_label1:
	m[intPow(4, 1)] = intPow(15, 1) - intPow((intPow(m[intPow(4, 1)], 1) - intPow(6, 1)), 1);
	m[intPow(5, 1)] = intPow(25, 1) / intPow(12, 1) * intPow(3, 1);
	m[intPow(6, 1)] = intPow(32, 1) + intPow(m[intPow(42, 1)], 1);
	m[intPow(7, 1)] = intPow(45, 1) - intPow(m[intPow(54, 1) - intPow(36, 1)], 1);
	m[intPow(8, 1)] = intPow(55, 1) - intPow((intPow(14, 1) - intPow(26, 1)), 1);
	m[intPow(9, 1)] = intPow(65, 1) - intPow(m[intPow((intPow(36, 1) - intPow(24, 1)), 1)], 1);
	printf("%d\n", intPow(m[intPow(3, 1)], 1));
	if(intPow(m[intPow(0, 1)], 1))
		goto my_label1;
	printf("%d\n", intPow(m[intPow(12, 1)], 1));
	goto my_label5;
	printf("%d\n", intPow(m[intPow(90, 1)], 1));
	my_label2:
	printf("%d\n", intPow(m[intPow(80, 1)], 1));
	return 0;
}
Beispiel #7
0
void chvprintf(BaseSequentialStream *chp, const char *fmt, va_list ap) {
  char *p, *s, c, filler;
  int i, precision, width;
  bool is_long, left_align;
  long l;
#if CHPRINTF_USE_FLOAT
  double d;
  char tmpbuf[2*MAX_FILLER + 1];
  int fprec=0;
#else
  char tmpbuf[MAX_FILLER + 1];
#endif

  while (TRUE) {
    c = *fmt++;
    if (c == 0) {
      return;
    }
    if (c != '%') {
      chSequentialStreamPut(chp, (uint8_t)c);
      continue;
    }
    p = tmpbuf;
    s = tmpbuf;
    left_align = false;
    if (*fmt == '-') {
      fmt++;
      left_align = true;
    }
    filler = ' ';
    if (*fmt == '.') {
      fmt++;
      filler = '0';
#if CHPRINTF_USE_FLOAT
      fprec = intPow (10, (*fmt)-'0');
#endif
    }
    width = 0;
    while (TRUE) {
      c = *fmt++;
      if (c >= '0' && c <= '9')
        c -= '0';
      else if (c == '*')
        c = va_arg(ap, int);
      else
        break;
      width = width * 10 + c;
    }
    precision = 0;
    if (c == '.') {
      while (TRUE) {
        c = *fmt++;
        if (c >= '0' && c <= '9') {
          c -= '0';
#if CHPRINTF_USE_FLOAT
          fprec = intPow (10, c);
#endif
        }
        else if (c == '*')
          c = va_arg(ap, int);
        else
          break;
        precision *= 10;
        precision += c;
      }
    }
Beispiel #8
0
int main(int argc, char *argv[]){
	int m[101];
	m[intPow(60, 1)] = intPow(m[intPow(60, 1)], 1) - intPow(1, 1);
	m[intPow(0, 1)] = intPow(5, 1) / intPow(2, 1) * intPow(3, 1);
	m[intPow(4, 1)] = intPow(88, 1) + intPow(2, 1);
	m[intPow(0, 1)] = intPow(5, 1) - intPow((intPow(m[intPow(4, 1)], 1) - intPow(6, 1)), 1);
	m[intPow(0, 1)] = intPow(m[intPow(15, 1)], 1) / intPow(2, 1) * intPow(3, 1);
	m[intPow(0, 1)] = intPow(2, 1) + intPow(m[intPow(2, 1)], 1);
	m[intPow(0, 1)] = intPow(5, 1) - intPow(m[intPow(4, 1) - intPow(6, 1)], 1);
	return 0;
}
Beispiel #9
0
int main(int argc, char *argv[]){
	int m[101];
	m[intPow(43, 1)] = intPow(5, 1) / intPow(2, 1) * intPow(3, 1);
	goto my_label4;
	m[intPow(15, 1)] = intPow(2, 1) + intPow(m[intPow(2, 1)], 1);
	m[intPow(56, 1)] = intPow(5, 1) - intPow(m[intPow(2, intPow(3, 1)) * intPow(2, 1) - intPow(2, 1)], 1) - intPow(6, 1);
	my_label1:
	m[intPow(75, 1)] = intPow(5, 1) - intPow((intPow(m[intPow(4, 1)], 1) - intPow(6, 1)), 1);
	m[intPow(68, 1)] = intPow(5, 1) / intPow(2, 1) * intPow(3, 1);
	goto my_label6;
	m[intPow(43, 1)] = intPow(2, 1) + intPow(m[intPow(2, 1)], 1);
	if(intPow(m[intPow(60, 1)], 1))
		goto my_label1;
	m[intPow(23, 1)] = intPow(5, 1) - intPow((intPow(m[intPow(4, 1)], 1) - intPow(6, 1)), 1);
	m[intPow(15, 1)] = intPow(2, 1) + intPow(m[intPow(2, 1)], 1);
	if(intPow(m[intPow(60, 1)], 1))
		goto my_label1;
	m[intPow(56, 1)] = intPow(5, 1) - intPow(m[intPow(4, intPow(2, 1)) * intPow(2, 1) - intPow(2, 1)], 1) - intPow(6, 1);
	my_label2:
	m[intPow(75, 1)] = intPow(5, 1) - intPow((intPow(m[intPow(4, 1)], 1) - intPow(6, 1)), 1);
	m[intPow(68, 1)] = intPow(5, 1) / intPow(2, 1) * intPow(3, 1);
	return 0;
}
//MAIN LOGIC BEGINS
int main() {

  //first unsigned int=total length of the actual representation, char = first 8 digits of the actual representation,
  //each KeyObject has these properties:
  //unsigned int unencodedLength; the total length of the unencoded number
  //unsigned int firstNDigits; the first 32 digits of the unencoded number
  //unsigned int primeRepresentation; the encoded representation of the number/key
  std::vector<KeyObject> keys;
  for(unsigned int i=0; i < 10000; i++){
      keys.push_back(KeyObject());
  }

  //unsigned int initialLowerBoundIndex = 0;
  //recursiveFillKeys(lowerBounds,upperBounds,initialLowerBoundIndex,keys,primes);

  //simple examle of generating the keys structure. (these are the numbers we will reduce the file to,
  //we store them in our ultra compact representation with some identifying info)
  //for (unsigned int i=6; i<10; i++){
  //  for (unsigned int j=6; j<10; j++){
  //    keys[(h-6)*16 + (i-6)*4 + (j-6)] = unsigned integerExponent(prime[0],i)*unsigned integerExponent(prime[1],j)....
  //  }
  //}

  Vvi input(build_input());
  std::cout << input << "\n";

  Vvi output;
  cart_product(input, output);
  std::cout << output << "\n";

  //sample input/output
  //input
  //  (
  //   (0, 1, 2, )
  //   (10, 11, 12, )
  //   (20, 21, 22, )
  //   )
  //  output
  //  (
  //   (0, 10, 20, )
  //   (1, 10, 20, )
  //   (2, 10, 20, )
  //   (0, 11, 20, )
  //   (1, 11, 20, )
  //   (2, 11, 20, )
  //   (0, 12, 20, )
  //   (1, 12, 20, )
  //   (2, 12, 20, )
  //   (0, 10, 21, )
  //   (1, 10, 21, )
  //   (2, 10, 21, )
  //   (0, 11, 21, )
  //   (1, 11, 21, )
  //   (2, 11, 21, )
  //   (0, 12, 21, )
  //   (1, 12, 21, )
  //   (2, 12, 21, )
  //   (0, 10, 22, )
  //   (1, 10, 22, )
  //   (2, 10, 22, )
  //   (0, 11, 22, )
  //   (1, 11, 22, )
  //   (2, 11, 22, )
  //   (0, 12, 22, )
  //   (1, 12, 22, )
  //   (2, 12, 22, ))
  unsigned int counter = 0;
  for(Vvi::iterator it = output.begin(); ; ) {
    //keyExponentValues gives us a vector with all the exponents we need to use
    //to create a key
    //here we calculate the number represented by the exponents

    mpz_t n;
    mpz_init(n);
    mpz_set(n,1);
    for (Vi::iterator keyExponentValues = it->begin(); ; ){
      mpz_t k;
      mpz_init(k);
      mpz_set(k,globals.primes[counter]);
      mpz_mul(n,n,k);
      n *= k;
      mpz_clear (k);
      //mpz_sizeinbase (mpz_t op, int base)
      //mpz_sizeinbase (mpz_t op, int base)
      //base can only be up to size 62 max!
      //here we store the length of the number represented by the exponents
      keys[counter].unencodedLength = 0;

      //here we store the first n digits of the number represented by the exponents
      keys[counter].firstNDigits = 0;
      mpz_clear (n);

      //this simulates log base 2
      unsigned int bitsToStoreExponent= 0;
      unsigned int exponentRange = globals.exponentMax - globals.exponentMin;
      while (exponentRange >>= 1) ++bitsToStoreExponent;
      //IMPORTANT ENCODING LOCATED RIGHT HERE IN THIS COMMENT!!!
      //00 = 6th power, 01=7th, 10=8th, 11=9th,
      //first 2 bits are for 2, next 2 are for 3, next 2 are for 5, etc. etc.
      unsigned int exponentCounter = 0;
      for(Vi::iterator keyExponentValues = it->begin(); ; ) {
        for (int j=globals.exponentMin; j<globals.exponentMax; j++){
          for (int k=0;k<bitsToStoreExponent;k++){
            //set i'th prime number bits to appropiate value between 0 and 2^k for exponent value j
            //globals.exponentMin - j want to turn this into binary representation, get appropriate number for ith place
            if (k==j){
              //keys[counter].primeRepresentation();
              //(globals.exponentMin - j) might be useful
              if (*keyExponentValues % intPow(2,k)==0){//base 10 number convert to base two, get ith digit.
                keys[counter].primeRepresentation.set(globals.howManyOfFirstNBitsStoredInKey
                                                      - exponentCounter*bitsToStoreExponent,1);
              }
              else{
                keys[counter].primeRepresentation.set(globals.howManyOfFirstNBitsStoredInKey
                                                      - exponentCounter*bitsToStoreExponent,0);
              }
            }
          }
        }
        //illustrative but less general example
        //switch(keyExponentValues->me[i]){
        //  case 6:
        //    keys[counter].primeRepresentation();
        //    keys[counter].primeRepresentation.set[32-i*2,0];
        //    keys[counter].primeRepresentation.set[31-i*2,0];
        //    break;
        //  case 7:
        //    keys[counter].primeRepresentation();
        //    keys[counter].primeRepresentation.set[32,0];
        //    keys[counter].primeRepresentation.set[31,1];
        //    break;
        //  case 8:
        //    keys[counter].primeRepresentation();
        //    keys[counter].primeRepresentation.set[32,1];
        //    keys[counter].primeRepresentation.set[31,0];
        //    break;
        //  case 9:
        //    keys[counter].primeRepresentation();
        //    keys[counter].primeRepresentation.set[32,1];
        //    keys[counter].primeRepresentation.set[31,1];
        //    break;
        //}
        exponentCounter++;
        keyExponentValues++;
      }
    }
    counter++;
    it++;
  }



  //HERE IS WHERE WE READ THE FILE IN THAT WE WILL ENCODE
  //TODO move this to a different section
  //char* input = getInputFromFile();

  //unsigned int i = 0;
  //while (input[i] != '\0'){
  //}
  return 0;
}