void TestPart2() 
{	std::cout << "\nTEST PART TWO" << std::endl;
	Matrix<std::string> a, b;
	a.ReadMatrix(); // User provides input for matrix a.
	std::cout << a << " ^ Matrix A\n" << std::endl;
	b.ReadMatrix(); // User provides input for matrix b. 
	std::cout << b << " ^ Matrix B\n" << std::endl;
	std::cout << a + b << " ^ A + B\n" << std::endl;
	Matrix<std::string> d = a + b;
	std::cout << d << " ^ D = A + B\n" << std::endl;
	std::cout << d + "hi_there" << " ^ D + \"hi_there\"\n" << std::endl;
	// Matrices should have same size.
	// The default + operator for strings 
	// will be used.
	PrintVec(a[1]);
	std::cout << " ^ PrintVec(a[1])\n" << std::endl;
	PrintVec(b[2]);
	std::cout << " ^ PrintVec(b[2])\n" << std::endl;
	// Should print the first row of a.
	// Should be print the second row of b.
	// Note, that the [] operator should return 
	// a vector object.
	// PrintVec() is a templated function that 
	// std::couts the elements of a vector.
} // End of TestPart2.
Exemple #2
0
int main()
{
    std::ofstream file( "myexample.txt" ) ;

    std::vector<double> one_d{ 0, 1, 2, 3, 4 } ;
    PrintVec( one_d, file ) ;

    std::vector< std::vector<double> > two_d{ { 0, 1, 2 },  { 3, 4 }, { 5 }, { 6, 7, 8, 9 } } ;
    PrintVec( two_d, file ) ;
}
Exemple #3
0
void TestEncrypt( void )
{
    //int32_t k=0;
    int32_t Nk=4, Nr=10;

    /* Plain Text:  00112233445566778899aabbccddeeff */
    uint8_t pt[AES_BLOCK_SIZE] = { 0x00, 0x11, 0x22, 0x33,
                                   0x44, 0x55, 0x66, 0x77,
                                   0x88, 0x99, 0xaa, 0xbb,
                                   0xcc, 0xdd, 0xee, 0xff };

    /* Key:         000102030405060708090a0b0c0d0e0f */
    uint8_t Key[AES_BLOCK_SIZE] = { 0x00, 0x01, 0x02, 0x03,
                                    0x04, 0x05, 0x06, 0x07,
                                    0x08, 0x09, 0x0a, 0x0b,
                                    0x0c, 0x0d, 0x0e, 0x0f };
    //uint8_t ZeroKey[AES_BLOCK_SIZE] = {0};

    uint8_t eKey[AES_MAX_KEY_SIZE] = {0};

    /* Cipher Text: 69c4e0d86a7b0430d8cdb78070b4c55a */

    KeyExpansion(eKey,Key,Nk,Nr);
    //for ( k=0; k<Nr+1; ++k )
    //{
    //    printf("%d\t",k);
    //    PrintVec(eKey+(AES_BLOCK_SIZE*k));
    //    printf("\n");
    //}
    RijndaelEncrypt(pt,eKey,Nr);
    printf("\n");
    PrintVec(pt);
    printf("\n");
}
 std::vector<std::string> wordBreak(std::string s, std::unordered_set<std::string>& dict) {
     if (m.count(s))
     {
         DEBUG("match!", s);
         return m[s];
     }
     std::vector<std::string> result;
     if (dict.count(s))
     {
         result.push_back(s);
     }
     for (int i = 1; i < s.size(); ++i)
     {
         std::string word = s.substr(i);
         DEBUG("word", word);
         if (dict.count(word))
         {
             std::string rem = s.substr(0, i);
             DEBUG("rem", rem);
             std::vector<std::string> prev = combine(word, wordBreak(rem, dict));
             result.insert(result.end(), prev.begin(), prev.end());
         }
     }
     DEBUG("s", s);
     PrintVec(s, result);
     m[s] = result;
     return result;
 }
Exemple #5
0
int main(int argc, char* arg[]) {

  int arr[][4] = { {1, 3, 5, 6}, {2, 4, 6, 7}, {3, 5, 7, 9}, {6, 7, 8, 10}  };
  
  int M = sizeof(arr) / sizeof(*arr);
  int N = sizeof(*arr) / sizeof(**arr);

  std::vector<std::vector<int> > my_vec;
  for ( int i = 0; i < M; ++i ) {
    std::vector<int> temp(*arr + (i*M), (*arr + (i * M )) + N);
    my_vec.push_back(temp);
  }

  PrintVec(my_vec);

  std::cout << SearchMatrix(my_vec, 0) << std::endl;

  
return 0;
}
Exemple #6
0
int main( void ) {


	//------------------------------------------------------

	//Ex 23 GLM:llä matriisi laskemista
	//glm::mat4 matrix1(1.0f, 0.0f, 2.0f, 2.0f,
	//				  0.0f, 1.0f, 0.0f, 0.0f,
	//				  1.0f, 1.0f, 1.0f, 2.0f,
	//				  0.0f, 0.0f, 1.0f, 0.0f);

	//glm::mat4 matrix2(0.0f, 0.0f, 0.0f, 2.0f,
	//				  1.0f, 1.0f, 0.0f, 0.0f,
	//				  1.0f, 1.0f, 0.0f, 2.0f,
	//				  0.0f, 0.0f, 1.0f, 0.0f);

	//glm::vec4 multiplyVector(3.0f, 4.0f, -2.0f, 1.0f);

	//glm::vec4 xTulos;

	//xTulos = (matrix1 * matrix2) * multiplyVector;

	///*for (int j = 0; j < sizeof(xTulos); j++)
	//{
	//	std::cout << xTulos[j] << std::endl;
	//}*/

	//std::cout << xTulos[0] << ", " << xTulos[1] << ", " << xTulos[2] << ", " << xTulos[3] << std::endl;

	//--------------------------------------------------------

	//Test
	//------------------------------------------------------
	
	std::cout << "Ex 25-------------------------------------------------------\n" << std::endl;
	glm::vec4 P1(0.0f, 0.0f, 0.0f, 1.0f);
	glm::vec4 P2(1.0f, 0.0f, 0.0f, 1.0f);
	glm::vec4 P3(0.0f, 1.0f, 0.0f, 1.0f);

	glm::vec3 x_axis(1.0f, 0.0f, 0.0f);
	glm::vec3 y_axis(0.0f, 1.0f, 0.0f);
	glm::vec3 z_axis(0.0f, 0.0f, 1.0f);

	glm::vec3 s(0.3f); //skaalaus
	glm::vec3 t(-2.0f, -1.0f, 0.0f); //siirto
	glm::vec3 r = z_axis; //kierto

	glm::mat4 R = rotate(3.14159265f / 6.0f, r);
	glm::mat4 S = scale(s);
	glm::mat4 T = translate(t);

	glm::mat4 T_total = T*S*R;
	PrintVec(T_total*P1);
	PrintVec(T_total*P2);
	PrintVec(T_total*P3);
	PrintMatrix(T_total);


	std::cout << "\nEx 26--------------------------------------------------------" << std::endl;
	glm::vec3 cam_pos(1.2f, 0.1f, 0.0);
	glm::vec3 cam_up = y_axis;
	glm::vec3 cam_right = x_axis;
	glm::vec3 cam_front = z_axis; //oikeakätinen koordinaatisto

	glm::mat4 C = lookAt(cam_pos, cam_pos + cam_front, cam_up);
	T_total = C*T_total;

	PrintVec(T_total*P1);
	PrintVec(T_total*P2);
	PrintVec(T_total*P3);
	PrintMatrix(T_total);

	std::cout << "\nEx 27---------------------------------------------------------" << std::endl;

	float v_width = 6.0; //viewport in camera coord
	float v_height = 6.0;

	glm::mat4  T_projection = glm::ortho(-0.5f*v_width, 0.5f*v_width,
		-0.5f*v_height, 0.5f*v_height);
	T_total = T_projection*T_total;
	PrintVec(T_total*P1);
	PrintVec(T_total*P2);
	PrintVec(T_total*P3);
	PrintMatrix(T_total);

	//------------------------------------------------------

	std::cout << "\n Ex 30--------------------------------------------------------" << std::endl;

	if (!glfwInit())
	{
		fprintf(stderr, "Failed to initialize GLFW\n");
		return -1;
	}

	glfwWindowHint(GLFW_SAMPLES, 4);
	glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
	glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
	glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);

	int w = 1024;
	int h = 768;
	window = glfwCreateWindow(w, h,
		"Tutorial 02 - Red triangle", NULL, NULL);
	if (window == NULL){
		fprintf(stderr, "Failed to open GLFW window.");
		glfwTerminate();
		return -1;
	}
	glfwMakeContextCurrent(window);
	glfwSetFramebufferSizeCallback(window, renderer::FramebufferSizeCallback);
	renderer::FramebufferSizeCallback(window, w, h);
	glewExperimental = true; // Needed for core profile
	if (glewInit() != GLEW_OK) {
		fprintf(stderr, "Failed to initialize GLEW\n");
		return -1;
	}

	glfwSetInputMode(window, GLFW_STICKY_KEYS, GL_TRUE);

	renderer::Init(window);

	do{
		renderer::Render();
		glfwPollEvents();
	} while (glfwGetKey(window, GLFW_KEY_ESCAPE) != GLFW_PRESS &&
		glfwWindowShouldClose(window) == 0);


	renderer::Uninit();
	glfwTerminate();

	//------------------------------------------------------
	// TESTI KOLMIO

	//if (!glfwInit())
	//{
	//	fprintf(stderr, "Failed to initialize GLFW\n");
	//	return -1;
	//}

	//glfwWindowHint(GLFW_SAMPLES, 4);
	//glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
	//glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
	//glfwWindowHint(GLFW_OPENGL_PROFILE,
	//	GLFW_OPENGL_CORE_PROFILE);

	//window = glfwCreateWindow(1024, 768,
	//	"Tutorial 02 - Red triangle", NULL, NULL);
	//if (window == NULL){
	//	fprintf(stderr, "Failed to open GLFW window.");
	//	glfwTerminate();
	//	return -1;
	//}
	//glfwMakeContextCurrent(window);
	//glewExperimental = true; // Needed for core profile
	//if (glewInit() != GLEW_OK) {
	//	fprintf(stderr, "Failed to initialize GLEW\n");
	//	return -1;
	//}

	//glfwSetInputMode(window, GLFW_STICKY_KEYS, GL_TRUE);
	//Init();

	//do{
	//	Render();
	//	glfwPollEvents();
	//} while (glfwGetKey(window, GLFW_KEY_ESCAPE) != GLFW_PRESS &&
	//	glfwWindowShouldClose(window) == 0);

	//glfwTerminate();
  
	//---------------------------------------------------------

	system("pause");

	return 0;
}
int main (int argc, char* argv[]){   
	int i, j, option;
	int size = 100;
	int b_print = 0;
	int range = 100;
	double **A, **T, **S;
	double *b;
	double temp;
	char* OUTPATH = "data_input";
	FILE* fp;

	srand(time(NULL));

	while ((option = getopt(argc, argv, "s:b:po:")) != -1)
		switch(option){
			case 's': size = strtol(optarg, NULL, 10); break;
			case 'b': range = strtol(optarg, NULL, 10);break;
			case 'p': b_print = 1; break;
			case 'o': OUTPATH = optarg; break;
			case '?': printf("Unexpected Options. \n"); return -1;
		}
	
	/*Generate the data*/
	A = CreateMat(size, size);
	T = CreateMat(size, size);
	S = CreateMat(size, size);
	b = malloc(size * sizeof(double));
	for (i = 0; i < size; ++i)
		for (j = 0; j < size; ++j){
			A[i][j] = 0;
			T[i][j] = 0;
		}
	MatGen(size, T, (double)range);
	GenPerm(size, A);
	MatMul(size, T, A, S);
	for (i = 0; i < size; ++i){
		temp = (double)(rand() % (int)(range * DECIMAL)) / DECIMAL;
		if (rand() % 2)
			temp *= -1;
		b[i] = temp;
	}
	/*Output the data*/
	if ((fp = fopen(OUTPATH,"w")) == NULL){
		printf("Fail to open a file to save the data. \n");
		return -2;
	}
	fprintf(fp, "%d\n\n", size);
	for (i = 0; i < size; ++i){
		for (j = 0; j < size; ++j)
			fprintf(fp, "%lf\t", S[i][j]);
		fprintf(fp, "\n");
	}
	fprintf(fp, "\n");
	for (i = 0; i < size; ++i)
		fprintf(fp, "%lf\n", b[i]);
	fclose(fp);
	/*Print the result if neccesary*/
	if (b_print){
		printf("The problem size is %d.\n", size);
		printf("============\n The A is \n============\n");
		PrintMat(S, size, size);
		printf("============\n The b is \n============\n");
		PrintVec(b, size);
	}
	DestroyMat(A, size);
	DestroyMat(T, size);
	DestroyMat(S, size);
	free(b);
	return 0;
}