コード例 #1
0
ファイル: closet_pair.cpp プロジェクト: lshi2004/Montevideo
// A recursive function to find the smallest distance. The array P contains
// all points sorted according to x coordinate
float closestUtil(Point P[], int n)
{
    // If there are 2 or 3 points, then use brute force
    if (n <= 3)
        return bruteForce(P, n);
 
    // Find the middle point
    int mid = n/2;
    Point midPoint = P[mid];
 
    // Consider the vertical line passing through the middle point
    // calculate the smallest distance dl on left of middle point and
    // dr on right side
    float dl = closestUtil(P, mid);
    float dr = closestUtil(P + mid, n-mid);
 
    // Find the smaller of two distances
    float d = min(dl, dr);
 
    // Build an array strip[] that contains points close (closer than d)
    // to the line passing through the middle point
    Point strip[n];
    int j = 0;
    for (int i = 0; i < n; i++)
        if (abs(P[i].x - midPoint.x) < d)
            strip[j] = P[i], j++;
 
    // Find the closest points in strip.  Return the minimum of d and closest
    // distance is strip[]
    return min(d, stripClosest(strip, j, d) );
}
コード例 #2
0
float ClosestPair(Point* pX, int n){
	if(n <= 3) return bruteForce(pX, n);
	
	//Chia mang thanh hai phan bang nhau
	int mid = n/2;
	Point midPoint = pX[mid];

	float dL = ClosestPair(pX, mid);
	printf("ClosestPairL %f\n", dL);
	float dR = ClosestPair(pX + mid,n-mid);
	printf("ClosestPairR %f\n", dR);
	
	float d = min(dL, dR);
	printf("ClosestPair %f\n", d);

	Point* pLR = (Point*) malloc (n * sizeof(Point));
	int k = 0;
	for (int i = 0; i < n; ++i){
		if (abs(pX[i].x - midPoint.x) <= d){
			pLR[k] = pX[i];
			k++;
		}
	}
	if (dmin > min(stripClosest(pLR, k, d), d)){
		dmin = min(stripClosest(pLR, k, d), d);
	}
	return min(stripClosest(pLR, k, d), d);;
}
コード例 #3
0
void cal(const char *a, const char *b)
{
	int maxLen, maxstart;

	maxstart = bruteForce(a, b, &maxLen);
	for(int i = 0; i < maxLen; i++)
		printf("%c", a[maxstart + i]);
	printf("\n");
}
コード例 #4
0
ファイル: P010.cpp プロジェクト: amclauth/Euler
 std::string execute(int variation)
 {
    switch (variation)
    {
       case 0:
          return to_string(bruteForce());
       case 1:
       case -1:
          return to_string(optimized());
       default:
          return std::string("unavailable");
    }
    return NULL;
 }
コード例 #5
0
ファイル: assn3.c プロジェクト: greptruth/algo_lab
float closest(point *A,long long N,point *u,point *v)
{
	if(N<3)
	{
		return bruteForce(A,N,u,v);
	}

	long long mid=N/2;
	point midPoint = A[mid];
	point a,b,r,s;
	long long i,j;


	double dl = closest(A, mid,&a,&b);
    double dr = closest(A + mid, N-mid,&r,&s);
    double d = min(dl, dr);
    if(dl<dr)
    {
    	u[0].x=a.x;u[0].y=a.y;
    	v[0].x=b.x;v[0].y=b.y;
    }
    else
    {
    	u[0].x=r.x;u[0].y=r.y;
    	v[0].x=s.x;v[0].y=s.y;
    }

    point strip[N];
    j=0;
    for (i = 0; i < N; i++)
        if (abs(A[i].x - midPoint.x) < d)
        {
            strip[j] = A[i];
            j++;
        }

    // return min(d, stripClosest(strip, j, d) );
    double minStrip = stripClosest(strip,j,d,&a,&b);
    if(d<minStrip)
    {
    	return d;
    }
    else
    {
    	u[0].x=a.x;u[0].y=a.y;
    	v[0].x=b.x;v[0].y=b.y;
    	return minStrip;
    }
}
コード例 #6
0
float closestUtil(Point P[], int n)
{
    if (n <= 3)
        return bruteForce(P, n);
 
    int mid = n/2;
    Point midPoint = P[mid];
 
    float dl = closestUtil(P, mid);
    float dr = closestUtil(P + mid, n-mid);
 
    float d = min(dl, dr);
 
    Point strip[n];
    int j = 0;
    for (int i = 0; i < n; i++)
        if (abs(P[i].x - midPoint.x) < d)
            strip[j] = P[i], j++;
 
    return min(d, stripClosest(strip, j, d) );
}
コード例 #7
0
void SudokubeSolver::solve(Sudokube& sudokube) {
	if(sudokube.isSolved()) {
		return;
	}

	if(simpleConstraintPropagation(sudokube)) {
		solve(sudokube);
		return;
	}else if(lastRemainingCellInARegion(sudokube)) {
		solve(sudokube);
		return;
	}else if(nakedPairs(sudokube)) {
		solve(sudokube);
		return;
	}else if(hiddenPairs(sudokube)) {
		solve(sudokube);
		return;
	}else if(hiddenTriples(sudokube)) {
		solve(sudokube);
		return;
	}else if(pointingPairs(sudokube)) {
		solve(sudokube);
		return;
	}else if(pointingTriples(sudokube)) {
		solve(sudokube);
		return;
	}else if(boxLineReductionPair(sudokube)) {
		solve(sudokube);
		return;
	}else if(boxLineReductionTriple(sudokube)) {
		solve(sudokube);
		return;
	}else {
		bruteForce(sudokube);
		return;
	}
	return;
}
コード例 #8
0
void testStringMatch(char * textbuffer, char * newtext, ordGrowthT horspool, ordGrowthT bruteforce, int index){
	int i, hFive, hTen, hTwenty, lFive, lTen, lTwenty;
	string pattern;
	resultT result;
	result = (resultT)GetBlock(sizeof * result);

	/****EXPERIMENT************/
	/**********HIGH************/
	/*
	printf("**********************************************************\n");
	printf("HORSPOOL\n\n");
	printf("Patterns consisting of the 5, 10 and 20 most common letters\nin the text will be generated\neach will be shuffled and retried 50 times.\n");
	*/
	pattern = generatePattern(5, textbuffer);
	for (i = 0; i < 50; i++){
		result->fivepat[i] = horSpool(newtext, randomPattern(pattern));
	}

	pattern = generatePattern(10, textbuffer);
	for (i = 0; i < 50; i++){
		result->tenpat[i] = horSpool(newtext, randomPattern(pattern));
	}

	pattern = generatePattern(20, textbuffer);
	for (i = 0; i < 50; i++){
		result->twentypat[i] = horSpool(newtext, randomPattern(pattern));
	}

	/********LOW*********/

	//printf("Patterns consisting of the 5, 10 and 20 LEAST common letters\nin the text will be generated\neach will be shuffled and retried 50 times.\n");

	pattern = generateLowPattern(5, textbuffer);
	for (i = 0; i < 50; i++){
		result->lowfivepat[i] = horSpool(newtext, randomPattern(pattern));
	}

	pattern = generateLowPattern(10, textbuffer);
	for (i = 0; i < 50; i++){
		result->lowtenpat[i] = horSpool(newtext, randomPattern(pattern));
	}

	pattern = generateLowPattern(20, textbuffer);
	for (i = 0; i < 50; i++){
		result->lowtwentypat[i] = horSpool(newtext, randomPattern(pattern));
	}

	//printf("MOST COMMON LETTERS\n");
	hFive = (sumArr(result->fivepat, 50) / 50);
	hTen = (sumArr(result->tenpat, 50) / 50);
	hTwenty = (sumArr(result->twentypat, 50) / 50);
	/*
	printf("5 letters: %d\n", hFive);
	printf("10 letters: %d\n", hTen);
	printf("20 letters: %d\n", hTwenty);
	*/
	horspool->five->nComps[index] = hFive;
	horspool->ten->nComps[index] = hTen;
	horspool->twenty->nComps[index] = hTwenty;

	//printf("LEAST COMMON LETTERS\n");
	lFive = (sumArr(result->lowfivepat, 50) / 50);
	lTen = (sumArr(result->lowtenpat, 50) / 50);
	lTwenty = (sumArr(result->lowtwentypat, 50) / 50);
	/*
	printf("5 letters: %d\n", lFive);
	printf("10 letters: %d\n", lTen);
	printf("20 letters: %d\n", lTwenty);
	*/
	horspool->lowfive->nComps[index] = lFive;
	horspool->lowten->nComps[index] = lTen;
	horspool->lowtwenty->nComps[index] = lTwenty;

	//printf("**********************************************************\n\n");
	


	/****EXPERIMENT************/
	/**********HIGH************/
	/*
	printf("**********************************************************\n");
	printf("BRUTEFORCE\n");
	printf("Patterns consisting of the 5, 10 and 20 most common letters\nin the text will be generated\neach will be shuffled and retried 50 times.\n");
	*/
	pattern = generatePattern(5, textbuffer);
	for (i = 0; i < 50; i++){
		result->fivepat[i] = bruteForce(newtext, randomPattern(pattern));
	}

	pattern = generatePattern(10, textbuffer);
	for (i = 0; i < 50; i++){
		result->tenpat[i] = bruteForce(newtext, randomPattern(pattern));
	}

	pattern = generatePattern(20, textbuffer);
	for (i = 0; i < 50; i++){
		result->twentypat[i] = bruteForce(newtext, randomPattern(pattern));
	}

	/********LOW*********/

	//printf("Patterns consisting of the 5, 10 and 20 LEAST common letters\nin the text will be generated\neach will be shuffled and retried 50 times.\n");

	pattern = generateLowPattern(5, textbuffer);
	for (i = 0; i < 50; i++){
		result->lowfivepat[i] = bruteForce(newtext, randomPattern(pattern));
	}

	pattern = generateLowPattern(10, textbuffer);
	for (i = 0; i < 50; i++){
		result->lowtenpat[i] = bruteForce(newtext, randomPattern(pattern));
	}

	pattern = generateLowPattern(20, textbuffer);
	for (i = 0; i < 50; i++){
		result->lowtwentypat[i] = bruteForce(newtext, randomPattern(pattern));
	}

	//printf("MOST COMMON LETTERS\n");
	hFive = (sumArr(result->fivepat, 50) / 50);
	hTen = (sumArr(result->tenpat, 50) / 50);
	hTwenty = (sumArr(result->twentypat, 50) / 50);
	/*
	printf("5 letters: %d\n", hFive);
	printf("10 letters: %d\n", hTen);
	printf("20 letters: %d\n", hTwenty);
	*/
	bruteforce->five->nComps[index] = hFive;
	bruteforce->ten->nComps[index] = hTen;
	bruteforce->twenty->nComps[index] = hTwenty;

	//printf("LEAST COMMON LETTERS\n");
	lFive = (sumArr(result->lowfivepat, 50) / 50);
	lTen = (sumArr(result->lowtenpat, 50) / 50);
	lTwenty = (sumArr(result->lowtwentypat, 50) / 50);
	/*
	printf("5 letters: %d\n", lFive);
	printf("10 letters: %d\n", lTen);
	printf("20 letters: %d\n", lTwenty);
	*/
	bruteforce->lowfive->nComps[index] = lFive;
	bruteforce->lowten->nComps[index] = lTen;
	bruteforce->lowtwenty->nComps[index] = lTwenty;

}
コード例 #9
0
ファイル: main.cpp プロジェクト: Lagrewj/CS325_Project2
int main(int argc, char* argv[])
{
    if (argc < 3)//cmd line arguments 
    {
	   std::cout << "Error! Error!" << std::endl;
	   std::cout << "Argument 1 is the program name" << std::endl;
	   std::cout << "Argument 2 is input file for greedy and dynamic programming algorithms." << std::endl;
	   std::cout << "Argument 3 is input file for brute force algorithm" << std::endl;
	   return 1;
    }
    
    //Hold input and output file names
    std::string input_filename;//Holds filename of first input file.
    std::string output_filename;//Holds filename of first output file.
    std::string input_filename2;//Holds filename of second input file.
    std::string output_filename2;//Holds filename of second output file.

    //Modify first output file name
    input_filename = argv[1];//Getting the first input filename via command line
    output_filename = input_filename;//Getting name for first output file
    output_filename.erase(output_filename.end() - 4, output_filename.end() - 0);//remove .txt from filename
    output_filename.append("change.txt");//appending change.txt to output_filename

    //Modify second output file name
    input_filename2 = argv[2];//Getting the second input filename via command line
    output_filename2 = input_filename2;//Getting name for second output file
    output_filename2.erase(output_filename2.end() - 4, output_filename2.end() - 0);//remove .txt from filename
    output_filename2.append("change.txt");//appending change.txt to output_filename

    std::cout << "1st INPUT FILE " << input_filename << std::endl;
    std::cout << "1st OUTPUT FILE " << output_filename << std::endl;
    std::cout << std::endl;
    std::cout << "2nd INPUT FILE " << input_filename2 << std::endl;
    std::cout << "2nd OUTPUT FILE " << output_filename2 << std::endl;
    std::cout << std::endl;

    std::string inputFile = input_filename;//first Input file name.
    std::ifstream if_inputStream;//input stream for first input file.

    std::string inputFile2 = input_filename2;//second Input file name.
    std::ifstream if_inputStream2;//input stream for second input file.

    //For first input file
    std::string tempFile = "temp.txt";//temp file name.
    std::fstream f_tempStream;//temp stream for temp file.

    //For second input file
    std::string tempFile2 = "temp2.txt";//temp2 file name.
    std::fstream f_tempStream2;//temp2 stream for temp file.

    std::string outputFile = output_filename;//first output file name.
    std::ofstream outputStream;//first output stream for output file.

    std::string outputFile2 = output_filename2;//second output file name.
    std::ofstream outputStream2;//second output stream for output file.

    output_file_check(outputStream, output_filename);//Checks if first output file is opened.
    output_file_check(outputStream2, output_filename2);//Checks if second output file is opened.
    if_file_check(if_inputStream, inputFile);//Checks to see if first input file is opened.
    if_file_check(if_inputStream2, inputFile2);//Checks to see if second input file is opened.
    f_file_check(f_tempStream, tempFile);//Check if temp file is opened
    f_file_check(f_tempStream2, tempFile2);//Check if temp2 file is opened

    std::vector<int> relay;// Holds values from array in first input file.
    std::vector<int> relay2;// Holds values from array in second input file.
    std::vector<int> coins;// Coins to calculate value from first input file.
    std::vector<int> coins2;// Coins to calculate value from second input file.
    int value;// Value to find with coins from first input file.
    int value2;// Value to find with coins from second input file.
    int arrayCount = 0;//Number of arrays in first input file.
    int arrayCount2 = 0;//Number of arrays in second input file.

    double time = 0; //Holds time for each array to be processed, used for greedy and DP algorithm run time
    double greedyTotalTime = 0;//Total run time for greedy algorithm
    double dpTotalTime = 0;//Total run time for DP algorithm

    //Variables used for brute force algorithm
    coinChange answer;//Keeps track of number of each coin used
    answer.num = 0;
    int minCoin;//Keeps track of total coins used.
    std::vector<int> storeCoin;//Vector to hold amount of each coin used.
    double bruteForceTotalTime = 0;//Total run time for brute force algorithm
    clock_t start, stop;//Used for calculating run time for brute force algorithm.

    //Strip first input file
    strip_file(if_inputStream, f_tempStream); //stripping first input file of [] and ,
    arrayCount = numofArrays(f_tempStream, tempFile);//Get count of number of arrays in first file.

    //Strip second input file
    strip_file(if_inputStream2, f_tempStream2); //stripping second input file of [] and ,
    arrayCount2 = numofArrays(f_tempStream2, tempFile2);//Get count of number of arrays in second file.

    //Iterate through the first input file for each array. Runs Greedy and DP algorithms
    for (int i = 1; i <= arrayCount + 1; i++)
    {
	   //First input file
	   relay = lineToVector(f_tempStream, tempFile, relay, i);//Populates relay vector with values.

	   if (i % 2 != 0)
	   {
		  coins = relay;//Set coins vector equal to relay.
		  relay.clear();//Clears the relay vector of all values.
	   }
	   else
	   {
		 value = relay[0];//Set value to the only index with a value in relay

		 /***************************GREEDY ALGORITHM**********************************/
		 //time = name_for_greedy_algorithm_function(outputStream, coins, value);
		 //greedyTotalTime += time;
		 //time = 03
		 
		 /***************************DP ALGORITHM**************************************/
		 //time = name_for_dp_algorithm_function(outputStream, coins, value);
		 //dpTotalTime += time;
		 //time = 0;

		 relay.clear();//Clears the relay vector of all values.
		 coins.clear();//Reset coins vector
		 value = 0;//Reset value
	   }
    }

    //Iterate through the second input file for each array. Runs brute force algorithm
    for (int i = 1; i <= arrayCount2 + 1; i++)
    {
	   //Reset timers;
	   start = 0;
	   stop = 0;
	   //Second input file
	   relay2 = lineToVector(f_tempStream2, tempFile2, relay2, i);//Populates relay vector with values.

	   if (i % 2 != 0)
	   {
		  coins2 = relay2;//Set coins vector equal to relay.
		  relay2.clear();//Clears the relay vector of all values.
	   }
	   else
	   {
		  value2 = relay2[0];//Set value to the only index with a value in relay

		  int arraySize2 = coins2.size();
		  start = clock();//Start timer
		  answer = bruteForce(coins2, value2, arraySize2);
		  stop = clock();//stop timer
		  bruteForceTotalTime += (stop - start) / double(CLOCKS_PER_SEC);

		  storeCoin.resize(arraySize2);//Sets the size of the amount of coins vector

		  for (int i = 0; i < arraySize2; i++)
		  {
			 storeCoin[i] = answer.coinCount[i];
		  }

		  minCoin = arraySum(answer.coinCount, arraySize2);

		  outputStream2 << "Brute Force Algorithm" << std::endl;
		  outputStream2 << "[";
		  for (int i = 0; i < arraySize2; i++)
		  {
			 if (i < (arraySize2 - 1))
			 {
				outputStream2 << storeCoin[i] << ", ";
			 }
			 else
			 {
				outputStream2 << storeCoin[i];
			 }
		  }
		  outputStream2 << "]";
		  outputStream2 << '\r' << '\n';
		  outputStream2 << minCoin << std::endl;
		  outputStream2 << '\r' << '\n';
		  outputStream2 << '\r' << '\n';

		  relay2.clear();//Clears the relay vector of all values.
		  coins2.clear();//Reset coins vector
		  value2 = 0;//Reset value
	   }
    }
    std::cout << "Alg1: Brute Force Run-time is: " << bruteForceTotalTime << std::endl;
    std::cout << "Alg2: Greedy Run-time is: " << greedyTotalTime << std::endl;
    std::cout << "Alg3: Dynamic Programming Run-time is: " << dpTotalTime << std::endl;

    //Closing file streams
    if_inputStream.close();
    if_inputStream2.close();
    f_tempStream.close();
    f_tempStream2.close();
    outputStream.close();
    outputStream2.close();

    return 0;

};//end main
コード例 #10
0
static void testQuadAngles(skiatest::Reporter* reporter, const SkDQuad& quad1, const SkDQuad& quad2,
        int testNo, SkChunkAlloc* allocator) {
    SkPoint shortQuads[2][3];

    SkOpContour contour;
    SkOpGlobalState state(NULL  PATH_OPS_DEBUG_PARAMS(&contour));
    contour.init(&state, false, false);
    makeSegment(&contour, quad1, shortQuads[0], allocator);
    makeSegment(&contour, quad1, shortQuads[1], allocator);
    SkOpSegment* seg1 = contour.first();
    seg1->debugAddAngle(0, 1, allocator);
    SkOpSegment* seg2 = seg1->next();
    seg2->debugAddAngle(0, 1, allocator);
    int realOverlap = PathOpsAngleTester::ConvexHullOverlaps(*seg1->debugLastAngle(),
            *seg2->debugLastAngle());
    const SkDPoint& origin = quad1[0];
    REPORTER_ASSERT(reporter, origin == quad2[0]);
    double a1s = atan2(origin.fY - quad1[1].fY, quad1[1].fX - origin.fX);
    double a1e = atan2(origin.fY - quad1[2].fY, quad1[2].fX - origin.fX);
    double a2s = atan2(origin.fY - quad2[1].fY, quad2[1].fX - origin.fX);
    double a2e = atan2(origin.fY - quad2[2].fY, quad2[2].fX - origin.fX);
    bool oldSchoolOverlap = radianBetween(a1s, a2s, a1e)
        || radianBetween(a1s, a2e, a1e) || radianBetween(a2s, a1s, a2e)
        || radianBetween(a2s, a1e, a2e);
    int overlap = quadHullsOverlap(reporter, quad1, quad2);
    bool realMatchesOverlap = realOverlap == overlap || SK_ScalarPI - fabs(a2s - a1s) < 0.002;
    if (realOverlap != overlap) {
        SkDebugf("\nSK_ScalarPI - fabs(a2s - a1s) = %1.9g\n", SK_ScalarPI - fabs(a2s - a1s));
    }
    if (!realMatchesOverlap) {
        DumpQ(quad1, quad2, testNo);
    }
    REPORTER_ASSERT(reporter, realMatchesOverlap);
    if (oldSchoolOverlap != (overlap < 0)) {
        overlap = quadHullsOverlap(reporter, quad1, quad2);  // set a breakpoint and debug if assert fires
        REPORTER_ASSERT(reporter, oldSchoolOverlap == (overlap < 0));
    }
    SkDVector v1s = quad1[1] - quad1[0];
    SkDVector v1e = quad1[2] - quad1[0];
    SkDVector v2s = quad2[1] - quad2[0];
    SkDVector v2e = quad2[2] - quad2[0];
    double vDir[2] = { v1s.cross(v1e), v2s.cross(v2e) };
    bool ray1In2 = v1s.cross(v2s) * vDir[1] <= 0 && v1s.cross(v2e) * vDir[1] >= 0;
    bool ray2In1 = v2s.cross(v1s) * vDir[0] <= 0 && v2s.cross(v1e) * vDir[0] >= 0;
    if (overlap >= 0) {
        // verify that hulls really don't overlap
        REPORTER_ASSERT(reporter, !ray1In2);
        REPORTER_ASSERT(reporter, !ray2In1);
        bool ctrl1In2 = v1e.cross(v2s) * vDir[1] <= 0 && v1e.cross(v2e) * vDir[1] >= 0;
        REPORTER_ASSERT(reporter, !ctrl1In2);
        bool ctrl2In1 = v2e.cross(v1s) * vDir[0] <= 0 && v2e.cross(v1e) * vDir[0] >= 0;
        REPORTER_ASSERT(reporter, !ctrl2In1);
        // check answer against reference
        bruteForce(reporter, quad1, quad2, overlap > 0);
    }
    // continue end point rays and see if they intersect the opposite curve
    SkDLine rays[] = {{{origin, quad2[2]}}, {{origin, quad1[2]}}};
    const SkDQuad* quads[] = {&quad1, &quad2};
    SkDVector midSpokes[2];
    SkIntersections intersect[2];
    double minX, minY, maxX, maxY;
    minX = minY = SK_ScalarInfinity;
    maxX = maxY = -SK_ScalarInfinity;
    double maxWidth = 0;
    bool useIntersect = false;
    double smallestTs[] = {1, 1};
    for (unsigned index = 0; index < SK_ARRAY_COUNT(quads); ++index) {
        const SkDQuad& q = *quads[index];
        midSpokes[index] = q.ptAtT(0.5) - origin;
        minX = SkTMin(SkTMin(SkTMin(minX, origin.fX), q[1].fX), q[2].fX);
        minY = SkTMin(SkTMin(SkTMin(minY, origin.fY), q[1].fY), q[2].fY);
        maxX = SkTMax(SkTMax(SkTMax(maxX, origin.fX), q[1].fX), q[2].fX);
        maxY = SkTMax(SkTMax(SkTMax(maxY, origin.fY), q[1].fY), q[2].fY);
        maxWidth = SkTMax(maxWidth, SkTMax(maxX - minX, maxY - minY));
        intersect[index].intersectRay(q, rays[index]);
        const SkIntersections& i = intersect[index];
        REPORTER_ASSERT(reporter, i.used() >= 1);
        bool foundZero = false;
        double smallT = 1;
        for (int idx2 = 0; idx2 < i.used(); ++idx2) {
            double t = i[0][idx2];
            if (t == 0) {
                foundZero = true;
                continue;
            }
            if (smallT > t) {
                smallT = t;
            }
        }
        REPORTER_ASSERT(reporter, foundZero == true);
        if (smallT == 1) {
            continue;
        }
        SkDVector ray = q.ptAtT(smallT) - origin;
        SkDVector end = rays[index][1] - origin;
        if (ray.fX * end.fX < 0 || ray.fY * end.fY < 0) {
            continue;
        }
        double rayDist = ray.length();
        double endDist = end.length();
        double delta = fabs(rayDist - endDist) / maxWidth;
        if (delta > 1e-4) {
            useIntersect ^= true;
        }
        smallestTs[index] = smallT;
    }
    bool firstInside;
    if (useIntersect) {
        int sIndex = (int) (smallestTs[1] < 1);
        REPORTER_ASSERT(reporter, smallestTs[sIndex ^ 1] == 1);
        double t = smallestTs[sIndex];
        const SkDQuad& q = *quads[sIndex];
        SkDVector ray = q.ptAtT(t) - origin;
        SkDVector end = rays[sIndex][1] - origin;
        double rayDist = ray.length();
        double endDist = end.length();
        SkDVector mid = q.ptAtT(t / 2) - origin;
        double midXray = mid.crossCheck(ray);
        if (gPathOpsAngleIdeasVerbose) {
            SkDebugf("rayDist>endDist:%d sIndex==0:%d vDir[sIndex]<0:%d midXray<0:%d\n",
                    rayDist > endDist, sIndex == 0, vDir[sIndex] < 0, midXray < 0);
        }
        SkASSERT(SkScalarSignAsInt(SkDoubleToScalar(midXray))
            == SkScalarSignAsInt(SkDoubleToScalar(vDir[sIndex])));
        firstInside = (rayDist > endDist) ^ (sIndex == 0) ^ (vDir[sIndex] < 0);
    } else if (overlap >= 0) {
        return;  // answer has already been determined
    } else {
        firstInside = checkParallel(reporter, quad1, quad2);
    }
    if (overlap < 0) {
        SkDEBUGCODE(int realEnds =)
                PathOpsAngleTester::EndsIntersect(*seg1->debugLastAngle(),
                *seg2->debugLastAngle());
        SkASSERT(realEnds == (firstInside ? 1 : 0));
    }
コード例 #11
0
ファイル: des.c プロジェクト: poojaag89/cracking-des
void* workerX(void *arg)
{
	int output56BitKey[56];
	int result = 0;
	struct worker_inputs *input=arg;
	printf("\n Worker : %d\n",input->workerid);
	//printf("\n start : %d\n",input->start);
	//printf("\n end : %d\n",input->end);

	result = bruteForce(plainText64Bit,cipher64Bit, input->start,input->end,output56BitKey,input->workerid);

	if(result == 1)
	{
		printf("\n---------- Worker %d found the key--------------->\n",input->workerid);
		printArray(output56BitKey,56,"KEY FOUND");

		if(isMaster == 1)
		{
			//MASTER - IFOUNDIT
			char ipAddress[16];
			char* message="MASTER - IFOUNDIT";

			memset(ipAddress,'\0',sizeof(ipAddress));
			strcpy(ipAddress, clientIPAddress[1]);
			messageSender(ipAddress, message);

			memset(ipAddress,'\0',sizeof(ipAddress));
			strcpy(ipAddress, clientIPAddress[2]);
			messageSender(ipAddress, message);

			memset(ipAddress,'\0',sizeof(ipAddress));
			strcpy(ipAddress, clientIPAddress[3]);
			messageSender(ipAddress, message);

			memset(ipAddress,'\0',sizeof(ipAddress));
			strcpy(ipAddress, clientIPAddress[4]);
			messageSender(ipAddress, message);

			memset(ipAddress,'\0',sizeof(ipAddress));
			strcpy(ipAddress, clientIPAddress[5]);
			messageSender(ipAddress, message);

			memset(ipAddress,'\0',sizeof(ipAddress));
			strcpy(ipAddress, clientIPAddress[6]);
			messageSender(ipAddress, message);



			//MASTER - STOP
			message="MASTER - STOP";

			memset(ipAddress,'\0',sizeof(ipAddress));
			strcpy(ipAddress, clientIPAddress[1]);
			messageSender(ipAddress, message);

			memset(ipAddress,'\0',sizeof(ipAddress));
			strcpy(ipAddress, clientIPAddress[2]);
			messageSender(ipAddress, message);

			memset(ipAddress,'\0',sizeof(ipAddress));
			strcpy(ipAddress, clientIPAddress[3]);
			messageSender(ipAddress, message);

			memset(ipAddress,'\0',sizeof(ipAddress));
			strcpy(ipAddress, clientIPAddress[4]);
			messageSender(ipAddress, message);

			memset(ipAddress,'\0',sizeof(ipAddress));
			strcpy(ipAddress, clientIPAddress[5]);
			messageSender(ipAddress, message);

			memset(ipAddress,'\0',sizeof(ipAddress));
			strcpy(ipAddress, clientIPAddress[6]);
			messageSender(ipAddress, message);

			exit(0);
		}
		else
		{
			char message[1024];
			char array[57];
			char workerName[56];
			//int g=0,h=0;

			memset(message,0x0,(sizeof(char)*1024));
			memset(workerName,0x0,(sizeof(char)*56));
			memset(array,0x0,(sizeof(char)*57));

			strcpy(message,"CLIENT - IFOUNDIT Key : ");
//			//24 char filled.
//			for(g=24,h=0;h<56;g++,h++)
//			{
//				message[g] = output56BitKey[h];
//			}
			sprintf(array,"%d%d%d%d%d%d%d%d%d%d%d%d%d%d%d%d%d%d%d%d%d%d%d%d%d%d%d%d%d%d%d%d%d%d%d%d%d%d%d%d%d%d%d%d%d%d%d%d%d%d%d%d%d%d%d%d"
					,output56BitKey[0],output56BitKey[1],output56BitKey[2],output56BitKey[3],output56BitKey[4],
					output56BitKey[5],output56BitKey[6],output56BitKey[7],output56BitKey[8],output56BitKey[9],
					output56BitKey[10],output56BitKey[11],output56BitKey[12],output56BitKey[13],output56BitKey[14],
					output56BitKey[15],output56BitKey[16],output56BitKey[17],output56BitKey[18],output56BitKey[19],
					output56BitKey[20],output56BitKey[21],output56BitKey[22],output56BitKey[23],output56BitKey[24],
					output56BitKey[25],output56BitKey[26],output56BitKey[27],output56BitKey[28],output56BitKey[29],
					output56BitKey[30],output56BitKey[31],output56BitKey[32],output56BitKey[33],output56BitKey[34],
					output56BitKey[35],output56BitKey[36],output56BitKey[37],output56BitKey[38],output56BitKey[39],
					output56BitKey[40],output56BitKey[41],output56BitKey[42],output56BitKey[43],output56BitKey[44],
					output56BitKey[45],output56BitKey[46],output56BitKey[47],output56BitKey[48],output56BitKey[49],
					output56BitKey[50],output56BitKey[51],output56BitKey[52],output56BitKey[53],output56BitKey[54],
					output56BitKey[55]);
			sprintf(workerName, " by Worker %d", input->workerid);

			strcat(message,array);

			strcat(message,workerName);

			printf("\n Send message to the Master that I found the key.\n");
			printf("\n Send the message to Master IP : %s \n",masterIPAddress);
			printf("\n Send the message : %s \n",message);
			messageSender(masterIPAddress, message);
			printf("\n Returned from messageSender\n");
		}
	}

	while(1)
	{
		//printf("\nWorker %d done brute forcing. Idling.\n",input->workerid);
		sleep(1);
	}

	return (0);
}