int main(){

	/*
	 * TEST 1
	 * Mid-Pt is missing
	 */
	{
		int myInts[] = {2,4,8,10,12,14};
		std::vector<int>arr1(myInts, myInts + sizeof(myInts) / sizeof(int) );
		printArray2(arr1,arr1.size());
		std::cout<<"Missing Elements in AP is: "<<findMissingElementAPExt(arr1,0,arr1.size())<<std::endl;
	}
	/*
	 * TEST 2
	 * Missing element is on left
	 */
	{
		int myInts[] = {2,6,8,10,12,14};
		std::vector<int>arr1(myInts, myInts + sizeof(myInts) / sizeof(int) );
		printArray2(arr1,arr1.size());
		std::cout<<"Missing Elements in AP is: "<<findMissingElementAPExt(arr1,0,arr1.size())<<std::endl;
	}
	/*
	 * TEST 3
	 * Missing element is on right
	 */
	{
		int myInts[] = {1,6,11,16,21,31};
		std::vector<int>arr1(myInts, myInts + sizeof(myInts) / sizeof(int) );
		printArray2(arr1,arr1.size());
		std::cout<<"Missing Elements in AP is: "<<findMissingElementAPExt(arr1,0,arr1.size())<<std::endl;
	}
	/*
	 * TEST 4
	 * Missing element is on right
	 */
	{
		int myInts[] = {1,6,16};
		std::vector<int>arr1(myInts, myInts + sizeof(myInts) / sizeof(int) );
		printArray2(arr1,arr1.size());
		std::cout<<"Missing Elements in AP is: "<<findMissingElementAPExt(arr1,0,arr1.size())<<std::endl;
	}
	/*
	 * TEST 5
	 * Everything is good
	 */
	{
		int myInts[] = {1,6,11};
		std::vector<int>arr1(myInts, myInts + sizeof(myInts) / sizeof(int) );
		printArray2(arr1,arr1.size());
		std::cout<<"Missing Elements in AP is: "<<findMissingElementAPExt(arr1,0,arr1.size())<<std::endl;
	}
	return 0;
}
Esempio n. 2
0
 bool isValidSudoku(vector<vector<char>>& board) {
     
     int ctr1 = 0, ctr2 = 0;
     for(int i = 0; i < 9; i ++){
         vector<bool> arr1(9, false);
         vector<bool> arr2(9, false);
         vector<bool> arr3(9, false);
         int x = (i/3) * 3;
         int y = (i * 3) % 9;
         for(int j = 0; j < 9; j ++){
             if(board[i][j] !='.'){
                if(arr1[board[i][j]-1 - '0']) return false;
                else arr1[board[i][j]-1 - '0'] = true;
             }
             if(board[j][i] !='.'){
                if(arr2[board[j][i]-1- '0']) return false;
                else arr2[board[j][i]-1- '0'] = true;
             }
             if(board[x + j % 3][y + j / 3] !='.'){
                if(arr3[board[x + j % 3][y + j / 3] - 1 - '0']) return false;
                else arr3[board[x + j % 3][y + j / 3] - 1 - '0'] = true;
             }
         }//end for j
     }//end for i
     return true;
 }
Esempio n. 3
0
void test2()
{
    ByteArray arr1("BC02");
    assert(arr1.size() == 2);
    assert(arr1[0] == 0xBC);
    assert(arr1[1] == 0x02);
    std::string s = arr1.as_string();
    assert(s.length() == 4);
    assert(strcmp(s.c_str(), "BC02") == 0);
}
Esempio n. 4
0
int
main(){
    UndoArray<char> arr1(7);
    arr1.set(3, 'R');
    arr1.set(3, 'D');
    arr1.undo(3);
    std::cout << arr1.get(3);
    //arr1.print();
    return 0;
}
Esempio n. 5
0
void test5()
{
    ByteArray arr("12345678");
    assert(arr.crc16() == 0x347B);
    assert(arr.checksum() == 236);
    ByteArray arr1("ABC12336dc");
    UINT_16 crc = arr1.crc16();
    assert(crc == 0xD7FF);
    arr1.append(crc);
    assert(arr1.as_string().compare("ABC12336DCD7FF") == 0);
}
Esempio n. 6
0
void test3()
{
    ByteArray arr1("BC02");
    ByteArray arr2("1234");
    arr1.append(arr2);
    assert(arr1.size() == 4);
    assert(arr1[0] == 0xBC);
    assert(arr1[1] == 0x02);
    assert(arr1[2] == 0x12);
    assert(arr1[3] == 0x34);
}
Esempio n. 7
0
int main()
{
	/////////////////////////////////////////////////////////////////////
	/// Exmaple for use:
	/////////////////////////////////////////////////////////////////////
	std::random_device rd;
	std::mt19937 gen(rd());
	std::uniform_int_distribution<> dis (-100, 100);

	std::vector <int> arr (25);
	std::vector <int> arr1 (25);
	std::vector <int> arr2 (25);

	for(int i = 0 ; i < 25; i++)
	{
		arr  [i] = dis (gen);
		arr1 [i] = arr [i];
		arr2 [i] = arr [i];
	}
	for (int i = 0 ; i < 25 ; i ++)
	{
		std::cout << arr [i] << " ";
	}
	std::cout << std::endl;

	////////////////////////////////////////////////////////////////////
	/// Use Standart Sort
	////////////////////////////////////////////////////////////////////
	std::sort (begin (arr1), end (arr1), cmp2 ());
	for (int i = 0 ; i < 25 ; i ++)
	{
		std::cout << arr1 [i] << " ";
	}
	std::cout << std::endl;

	/////////////////////////////////////////////////////////////////////
	/// Use atdc sort
	/////////////////////////////////////////////////////////////////////
	atdc_sort (std::begin (arr2), std::end (arr2), cmp1 ());
	
	for(int i = 0 ; i < (int)arr2.size () ; i ++)
	{
		std::cout << arr2 [i] << " ";
	}
	std::cout << std::endl;
	return 0;
}
Esempio n. 8
0
//-----------------------------------------------------------------------------
// Returns true if a array attribute is equal
//-----------------------------------------------------------------------------
static bool IsArrayEqual( CDmElement *pElement1, CDmElement *pElement2, const char *pArrayAttribute )
{
	CDmrElementArray<> arr1( pElement1, pArrayAttribute );
	CDmrElementArray<> arr2( pElement2, pArrayAttribute );
	int nCount = arr1.IsValid() ? arr1.Count() : 0;
	int nCount2 = arr2.IsValid() ? arr2.Count() : 0;
	if ( nCount != nCount2 )
		return false;
	for ( int i = 0; i < nCount; ++i )
	{
		if ( !IsScalarAttributesEqual( arr1[i], arr2[i] ) )
			return false;
	}

	return true;

}
Esempio n. 9
0
int main(){

	Array<double, int> arr1(10); // start index = 1
	Array<double, int> arr2(10,-1); // start index = -1
	Array<double, int> arr3(10, 0, 3.14); // start index = 0, all values = 3.14

	print(arr1);
	print(arr2);
	print(arr3);

	Matrix<double, int> m1(10, 10);
	Matrix<double, int> m2(10, 10, -2, 3.14);

	print(m1);
	print(m2);

	return 0;
}
Esempio n. 10
0
void main()
{
    int val;
    array arr1(5);
    arr1.input();
    val = arr1.getsize();
    cout<<"Size of Array is :"<<val<<endl;
    arr1.display();
    arr1.setat(3, 90);
    arr1.display();
    val = arr1.getat(2);
    if(val != 0)
        cout<<"Element at Index 2 is :"<<val<<endl;
    else
        cout<<"You have entered incorrect Index"<<endl;
    arr1.sort();
    arr1.display();
}
Esempio n. 11
0
//-----------------------------------------------------------------------------
// Returns true if a def is equal
//-----------------------------------------------------------------------------
static bool IsDefEqual( CDmElement *pElement1, CDmElement *pElement2 )
{
	if ( !IsScalarAttributesEqual( pElement1, pElement2 ) )
		return false;
	if ( !IsArrayEqual( pElement1, pElement2, "renderer" ) )
		return false;
	if ( !IsArrayEqual( pElement1, pElement2, "operator" ) )
		return false;
	if ( !IsArrayEqual( pElement1, pElement2, "initializer" ) )
		return false;
	if ( !IsArrayEqual( pElement1, pElement2, "emitter" ) )
		return false;
	if ( !IsArrayEqual( pElement1, pElement2, "forcegenerator" ) )
		return false;
	if ( !IsArrayEqual( pElement1, pElement2, "constraint" ) )
		return false;
	if ( !IsArrayEqual( pElement1, pElement2, "children" ) )
		return false;

	CDmrElementArray<> arr1( pElement1, "children" );
	CDmrElementArray<> arr2( pElement2, "children" );
	int nCount = arr1.IsValid() ? arr1.Count() : 0;
	int nCount2 = arr2.IsValid() ? arr2.Count() : 0;
	if ( nCount != nCount2 )
		return false;
	for ( int i = 0; i < nCount; ++i )
	{
		CDmElement *pChild1 = arr1[i]->GetValueElement<CDmElement>( "child" );
		CDmElement *pChild2 = arr2[i]->GetValueElement<CDmElement>( "child" );
		if ( !pChild1 || !pChild2 )
		{
			if ( pChild1 || pChild2 )
				return false;
			continue;
		}
		if ( !IsDefEqual( pChild1, pChild2 ) )
			return false;
	}

	return true;
}
Esempio n. 12
0
int Solution::maxArr(vector<int> &A) {
    int ans = INT_MIN;
    vector<int> arr1(A.size()+1), arr2(A.size()+1);
    
    for(int i=0; i<A.size(); i++){
        arr1[i] = A[i]+(i+1);
        arr2[i] = A[i]-(i+1);
    }
    
    int max1=INT_MIN, max2=INT_MIN, min1=INT_MAX, min2=INT_MAX;
    
    for(int i=0; i<A.size(); i++){
        max1=max(max1, arr1[i]);
        max2=max(max2, arr2[i]);
        
        min1=min(min1, arr1[i]);
        min2=min(min2, arr2[i]);
    }
    
    
    return max(abs(max1-min1), abs(max2-min2));
}
Esempio n. 13
0
int main() {
	RLIdentRegister* iregister = new RLIdentRegister();
    RLType::setRegister(iregister);

    std::cout << "Test 1\n";
    RLArray array(RLType::Number);

    array.setElem(1,&RLNumber(100));
    array.setElem(2,&RLNumber(112));
    array.setElem(2,&RLBool(false));

    //array.print();

    RLArray* array2 = array.copy();

    std::cout << array.applyBinary(compare,array2) << std::endl;

    array2->getElem(2)->applyUnary(increment);

    std::cout << array.applyBinary(compare,array2) << std::endl;

    array.print();
    array2->print();

    std::cout << "Test 1\n";
    RLArray arr1(RLType::Number);
    RLArray arr2(RLType::Number);

    arr1.setElem(1,&RLNumber(101));
    arr1.setElem(2,&RLNumber(102));

    arr1.setElem(2,&RLNumber(101));
    arr1.setElem(1,&RLNumber(102));

    std::cout << arr1.applyBinary(compare,&arr2) << std::endl;

	delete iregister;
}
Esempio n. 14
0
TEST_P(TestGetSubPatch3D, SubPatch)
{
  Go::SplineVolume vol(GetParam().n, GetParam().n, GetParam().n,
      GetParam().p+1, GetParam().p+1, GetParam().p+1,
      GetParam().knots.begin(), GetParam().knots.begin(), GetParam().knots.begin(),
      GetParam().coefs.begin(), GetParam().dim, GetParam().rational);
  size_t numcoefs0 = vol.basis(0).numCoefs()/2 + GetParam().p;
  Go::SplineVolume vol0 = MultiPatchModelGenerator3D::getSubPatch(&vol,
      0, numcoefs0, GetParam().p+1,
      0, numcoefs0, GetParam().p+1,
      0, numcoefs0, GetParam().p+1);
  size_t numcoefs1 = vol.basis(0).numCoefs() - numcoefs0 + GetParam().p;
  size_t start1 = numcoefs0 - GetParam().p;
  Go::SplineVolume vol1 = MultiPatchModelGenerator3D::getSubPatch(&vol,
      start1, numcoefs1, GetParam().p+1,
      0, numcoefs0, GetParam().p+1,
      0, numcoefs0, GetParam().p+1);

  // Check first sub-knot-vector
  std::vector<double> arr0(GetParam().knots.begin(), GetParam().knots.begin()+GetParam().lknots0);
  std::vector<double> arr1(vol0.basis(0).begin(), vol0.basis(0).end());
  std::cout << "sub-knot-vector 0" << std::endl;
  check_vector_double_near(arr0, arr1);

  // Check second sub-knot-vector
  std::vector<double> arr2(GetParam().knots.end()-GetParam().lknots1, GetParam().knots.end());
  std::vector<double> arr3(vol1.basis(0).begin(), vol1.basis(0).end());
  std::cout << "sub-knot-vector 1" << std::endl;
  check_vector_double_near(arr2, arr3);
  std::vector<double> arrX(vol.coefs_begin(), vol.coefs_end());

  // Check first sub-control net
  std::vector<double>::const_iterator i0 = GetParam().rational ? vol0.rcoefs_begin() : vol0.coefs_begin();
  std::vector<double>::const_iterator i1 = GetParam().rational ? vol0.rcoefs_end() : vol0.coefs_end();
  std::vector<double> arr4(i0, i1);
  std::cout << "sub-node-vector 0" << std::endl;
  check_vector_double_near(GetParam().coefs0, arr4);

  // Check second sub-control net
  std::vector<double>::const_iterator i2 = GetParam().rational ? vol1.rcoefs_begin() : vol1.coefs_begin();
  std::vector<double>::const_iterator i3 = GetParam().rational ? vol1.rcoefs_end() : vol1.coefs_end();
  std::vector<double> arr5(i2, i3);
  std::cout << "sub-node-vector 1" << std::endl;
  check_vector_double_near(GetParam().coefs1, arr5);

  // Evaluate function at points
  double xiA(0.3333), xiB(2), xiC(4.2);
  RealFunc* f = utl::parseRealFunc("(1-y*y)*(3.14159-x)*(1-z)", "expression");
  Go::SplineVolume* fh = SplineUtils::project(&vol, *f);
  Go::SplineVolume fh0 = MultiPatchModelGenerator3D::getSubPatch(fh,
      0, numcoefs0, GetParam().p+1,
      0, numcoefs0, GetParam().p+1,
      0, numcoefs0, GetParam().p+1);
  Go::SplineVolume fh1 = MultiPatchModelGenerator3D::getSubPatch(fh,
      start1, numcoefs1, GetParam().p+1,
      0, numcoefs0, GetParam().p+1,
      0, numcoefs0, GetParam().p+1);
  Go::Point fA, fB, fC, fA0, fB0, fB1, fC1;
  fh->point(fA, xiA, xiA, xiA);
  fh->point(fB, xiB, xiA, xiA);
  fh->point(fC, xiC, xiA, xiA);

  std::cout << "point evaluation" << std::endl;
  fh0.point(fA0, xiA, xiA, xiA);
  check_point_near(fA, fA0);
  fh0.point(fB0, xiB, xiA, xiA);
  check_point_near(fB, fB0);
  fh1.point(fB1, xiB, xiA, xiA);
  check_point_near(fB, fB1);
  fh1.point(fC1, xiC, xiA, xiA);
  check_point_near(fC, fC1);

  // Check FEM topology
  std::stringstream str0, str1;
  str0 << "700 1 0 0\n" << vol0;
  str1 << "700 1 0 0\n" << vol1;
  ASMs3D pch0, pch1;
  pch0.resetNumbering();
  pch0.read(str0);
  pch1.read(str1);
  std::cout << "element/node numbers" << std::endl;
  ASSERT_TRUE(pch0.generateFEMTopology());
  ASSERT_TRUE(pch1.generateFEMTopology());
  std::vector<int> myMLGE = pch1.getMyElementNums();
  check_vector_int_equals_range(myMLGE, GetParam().mlge1);
  std::vector<int> myMLGN = pch1.getMyNodeNums();
  check_vector_int_equals_range(myMLGN, GetParam().mlgn1);
}
double kshell_tri_interp(vector<double> &x, vector<double> &y, vector<double> &z, vector<double> &data, double x0, double y1, double z1, int KK)
{
  //cout << "Entering kshel" << endl;
  int NI = 53;
  int NJ = 60;
  int NK = 65;
  double p[NI][NJ];
  double q[NI][NJ];
  double data1[NI][NJ];
  double d = 0.0;
  double p1,q1;

  for(int i = 0; i < NI; i++)
  {
    for(int j = 0; j < NJ; j++)
    {
      p[i][j] = x[shellIndex(i,j,KK)];
      q[i][j] = sqrt(pow(y[shellIndex(i,j,KK)],2.0)+pow(z[shellIndex(i,j,KK)],2.0));
      p1=x0;
      q1=sqrt(pow(y1,2.0)+pow(z1,2.0));
      data1[i][j] = data[shellIndex(i,j,KK)];
    }
  }

  //Find out which triangle is (p1.q1) in
  //search through (i,j) pairs, each cell is divided into two triangles
  // 1 (i,j) (i+1,j),(i,j+1)
  // 2 (i+1,j+1) (i+1,j), (i,j+1)

  double s1[2];
  double s2[2];
  double s3[2];
  double s4[2];
  double xx1,yy1,ff1,xx2,yy2,ff2,xx3,yy3,ff3;

  for(int i = 0; i < NI-1; i++)
  {
    for(int j = 0; j < NJ-1; j++)
    {
      s1[0] = p[i][j]-p1;
      s1[1] = q[i][j]-q1;
      s2[0] = p[i+1][j]-p1;
      s2[1] = q[i+1][j]-q1;
      s3[0] = p[i+1][j+1]-p1;
      s3[1] = q[i+1][j+1]-q1;
      s4[0] = p[i][j+1]-p1;
      s4[1] = q[i][j+1]-q1;

      //Triangle 1, ANG(12)+ANG(24)+ANG(41)=2*pi
      double theta12, theta24, theta41;
      theta12=acos((s1[0]*s2[0]+s1[1]*s2[1])/sqrt((pow(s1[0],2)+pow(s1[1],2))*(pow(s2[0],2)+pow(s2[1],2))));
      theta24=acos((s2[0]*s4[0]+s2[1]*s4[1])/sqrt((pow(s2[0],2)+pow(s2[1],2))*(pow(s4[0],2)+pow(s4[1],2))));
      theta41=acos((s4[0]*s1[0]+s4[1]*s1[1])/sqrt((pow(s4[0],2)+pow(s4[1],2))*(pow(s1[0],2)+pow(s1[1],2))));

      if(abs(theta12+theta24+theta41-2.0*PI) < 0.001)
      {
        xx1=p[i][j];
        yy1=q[i][j];
        ff1=data1[i][j];
        xx2=p[i+1][j];
        yy2=q[i+1][j];
        ff2=data1[i+1][j];
        xx3=p[i][j+1];
        yy3=q[i][j+1];
        ff3=data1[i][j+1];
        break;
      }

      //Triangle 2, ANG(23)+ANG(34)+ANG(42)=2*pi
      double theta23, theta34, theta42;
      theta23=acos((s2[0]*s3[0]+s2[1]*s3[1])/sqrt((pow(s2[0],2)+pow(s2[1],2))*(pow(s3[0],2)+pow(s3[1],2))));
      theta34=acos((s3[0]*s4[0]+s3[1]*s4[1])/sqrt((pow(s3[0],2)+pow(s3[1],2))*(pow(s4[0],2)+pow(s4[1],2))));
      theta42=acos((s4[0]*s2[0]+s4[1]*s2[1])/sqrt((pow(s4[0],2)+pow(s4[1],2))*(pow(s2[0],2)+pow(s2[1],2))));


      if(abs(theta23+theta34+theta42-2.0*PI) < 0.001)
      {
        xx1=p[i+1][j+1];
        yy1=q[i+1][j+1];
        ff1=data1[i+1][j+1];
        xx2=p[i+1][j];
        yy2=q[i+1][j];
        ff2=data1[i+1][j];
        xx3=p[i][j+1];
        yy3=q[i][j+1];
        ff3=data1[i][j+1];
        break;
      }

    }
  }

  Array2D< double > arr1(3,3);
  Array2D< double > arr2(3,3);
  Array2D< double > arr3(3,3);
  Array2D< double > arr(3,3);

  double temp[3][3] = { {xx1, yy1, 1},
                       {xx2, yy2, 1},
                       {xx3, yy3, 1}};
  for(int i=0;i<3;i++){
    for(int j=0;j<3;j++){
      arr[i][j] = temp[i][j];
    }
  }

  double temp1[3][3] = { {p1, q1, 1},
                        {xx2, yy2, 1},
                        {xx3, yy3, 1}};
  for(int i=0;i<3;i++){
    for(int j=0;j<3;j++){
      arr1[i][j] = temp1[i][j];
    }
  }

  double temp2[3][3] = { {p1, q1, 1},
                        {xx1, yy1, 1},
                        {xx3, yy3, 1}};
  for(int i=0;i<3;i++){
    for(int j=0;j<3;j++){
      arr2[i][j] = temp2[i][j];
    }
  }

  double temp3[3][3] = { {p1, q1, 1},
                        {xx1, yy1, 1},
                        {xx2, yy2, 1}};
  for(int i=0;i<3;i++){
    for(int j=0;j<3;j++){
      arr3[i][j] = temp3[i][j];
    }
  }

  JAMA::LU< double > compute(arr);
  JAMA::LU< double > compute1(arr1);
  JAMA::LU< double > compute2(arr2);
  JAMA::LU< double > compute3(arr3);

  d = (ff1*compute1.det() - ff2*compute2.det() + ff3*compute3.det())/compute.det();


  return d;


}
Esempio n. 16
0
TEST(Stack_DgVariableArray2D, creation_DgVariableArray2D)
{
  Dg::VariableArray2D<int> arr;

  int x0[3] = {0, 1, 2};
  int x1[2] = {3, 4};
  int x2[4] = {5, 6, 7, 8};
  int x3[1] = {9};
  int x4[5] = {10, 11, 12, 13, 14};

  arr.push_back(x0, 3);
  arr.push_back(x1, 2);
  arr.push_back(x2, 4);
  arr.push_back(x3, 1);
  arr.push_back(x4, 5);

  CHECK(arr(0, 0) == 0);
  CHECK(arr(0, 1) == 1);
  CHECK(arr(0, 2) == 2);
  CHECK(arr(1, 0) == 3);
  CHECK(arr(1, 1) == 4);
  CHECK(arr(2, 0) == 5);
  CHECK(arr(2, 1) == 6);
  CHECK(arr(2, 2) == 7);
  CHECK(arr(2, 3) == 8);
  CHECK(arr(3, 0) == 9);
  CHECK(arr(4, 0) == 10);
  CHECK(arr(4, 1) == 11);
  CHECK(arr(4, 2) == 12);
  CHECK(arr(4, 3) == 13);
  CHECK(arr(4, 4) == 14);

  Dg::VariableArray2D<int> arr1(arr);
  Dg::VariableArray2D<int> arr2 = arr;

  CHECK(arr1(0, 0) == 0);
  CHECK(arr1(0, 1) == 1);
  CHECK(arr1(0, 2) == 2);
  CHECK(arr1(1, 0) == 3);
  CHECK(arr1(1, 1) == 4);
  CHECK(arr1(2, 0) == 5);
  CHECK(arr1(2, 1) == 6);
  CHECK(arr1(2, 2) == 7);
  CHECK(arr1(2, 3) == 8);
  CHECK(arr1(3, 0) == 9);
  CHECK(arr1(4, 0) == 10);
  CHECK(arr1(4, 1) == 11);
  CHECK(arr1(4, 2) == 12);
  CHECK(arr1(4, 3) == 13);
  CHECK(arr1(4, 4) == 14);

  CHECK(arr2(0, 0) == 0);
  CHECK(arr2(0, 1) == 1);
  CHECK(arr2(0, 2) == 2);
  CHECK(arr2(1, 0) == 3);
  CHECK(arr2(1, 1) == 4);
  CHECK(arr2(2, 0) == 5);
  CHECK(arr2(2, 1) == 6);
  CHECK(arr2(2, 2) == 7);
  CHECK(arr2(2, 3) == 8);
  CHECK(arr2(3, 0) == 9);
  CHECK(arr2(4, 0) == 10);
  CHECK(arr2(4, 1) == 11);
  CHECK(arr2(4, 2) == 12);
  CHECK(arr2(4, 3) == 13);
  CHECK(arr2(4, 4) == 14);
}