Example #1
0
int main(){
	int p[10000],a[10000];
	int c=getPrimeHash(p,10000,a);
	int i=0;
	while(1){
		//printf("\na[%d] = %d",i,a[i]);
		if(a[i]>1000){
			break;
		}
		i++;
	}
	//printf("\na[i] = %d \n",a[i]);
	int j,x,y;
	while(i<c){
		//printf("\ni = %d\n",i);
		j=2;
		while((a[i]+2*j)<10000){
			x=a[i]+j;
			y=a[i]+2*j;
			if(isPermutation(a[i],x)==1&&isPermutation(a[i],y)==1){
				if((p[x-1]==0)&&(p[y-1]==0)){
					printf("\n%d %d %d ANS = %d%d%d",a[i],x,y,a[i],x,y);
				}
			}
			j=j+2;
		}
		i++;
	}
}
Example #2
0
int solve70() {
	int result = 0;
	float bestRatio = 10;
	auto primes = sieve( 5000 );

	for( int i = 0; i < primes.size(); ++i ) {
		for( int j = i + 1; j < primes.size(); ++j ) {
			int n = primes[i] * primes[j];

			if( n > 10000000 ) {
				break;
			}

			int totatives = ( primes[i] - 1 ) * ( primes[j] - 1 );
			float ratio = float( n ) / float( totatives );

			if( ratio < bestRatio ) {
				if( isPermutation( n, totatives ) ) {
					result = n;
					bestRatio = ratio;
				}
			}
		}
	}

	return result;
}
  void OptimisationProblem<T>::setParameterPermutation(
      const arma::Col<unsigned int>& parameterPermutation) {
    verify(parameterPermutation.n_elem == numberOfDimensions_, "The number of elements must be equal to the number of dimensions");
    verify(isPermutation(parameterPermutation, numberOfDimensions_, numberOfDimensions_), "The parameter must be a permutation.");

    parameterPermutation_ = parameterPermutation;

    // Resets all counters and caches, as the problem could be changed.
    reset();
  }
Example #4
0
int main(){

    string str1 = "abc";
    string str2 = "aaa";
    
    if(isPermutation(str1,str2)){
        printf("Permutation\n");
    }else{
        printf("Not Permutation\n");
    }
}
Example #5
0
int main(){

    char str1[] = "123654Hello";
    char str2[] = "5H4l1e2l3o6";

    printf("Comparing %s against %s \n",str1,str2);
    if(isPermutation(str1,str2)){
        printf(" is a permutation  \n");
    }else{
        printf(" is NOT a permutation  \n");
    }

    return 0;

}
Example #6
0
int main (void)
{
  int i;
  int a[5] = {5,3,2,4,1};
  int b[5] = {-1, 0, 0, 0, 1};
  int c[5] = {-10, 9, -8 , 7, -6};

  printf("max(a, 5) = %d\n", max(a, 5));
  printf("countValue (a, 5, 1) = %d\n", countValue (a, 5, 1));
  printf("countValue (a, 5, 0) = %d\n", countValue (a, 5, 0));
  printf("isSorted (a, 5) = %d\n", isSorted (a, 5));
  printf("isPermutation (a, 5) = %d\n", isPermutation (a, 5));

  printf("max(b, 5) = %d\n", max(b, 5));
  printf("countValue (b, 5, 1) = %d\n", countValue (b, 5, 1));
  printf("countValue (b, 5, 0) = %d\n", countValue (b, 5, 0));
  printf("isSorted (b, 5) = %d\n", isSorted (b, 5));
  printf("isPermutation (b, 5) = %d\n", isPermutation (b, 5));

  absolute (c, 5);
  for (i = 0; i < 5; i++)
    printf ("c[%d] = %d\n", i, c[i]);
  return 0;
}
Example #7
0
int main()
{
    for (Natural n = 1; true; ++n) {
        bool required = true;
        for (int mult = 2; mult <= 6; ++mult) {
            if (not isPermutation(n, n * mult)) {
                required = false;
                break;
            }
        }
        if (required) {
            std::cout << n << std::endl;
            break;
        }
    }
    return 0;
}
Example #8
0
int main(){
    
    char str1[MAXARRAYSIZE], str2[MAXARRAYSIZE];
    
    printf("Enter String1..!!\n");
    scanf("%s" , str1);
    printf("Enter String1..!!\n");
    scanf("%s" , str2);
    
    int result = isPermutation(str1 , str2);
    
    if(result == 0)
        printf("Strings are permutation of each other..!!\n");
    else
        printf("Strings are not permutation of each other..!!\n");
    
    return 0;
}
Example #9
0
int main(int argc, char **argv)
{
    // printf("the answer is %d\n", isPermutation(714285, 1428570));
    int i = 100;
    for(;;i++)
    {
        int counter = 2;
        int same = 1;
        for(;counter <= HIGHEST_MULTIPLE; counter++)
        {
            same = same && isPermutation(i, counter * i);
        }
        if(same)
        {
            printf("The number is %d\n", i);
            break;
        }
    }
    return 0;
}
Example #10
0
int main()
{
    int i,n;
    double p,min=2147483647.0,ph,epsilon=0.000000001;
    for(i=2;i<MAX;i++)
    {
        if(i%100000==0)
            printf("%d\n",i);
        ph=(double)phi(i);
        if(isPermutation(i,ph))
        {
            p=n/ph;
            if(min-p > epsilon)
            {
                min=p;
                n=i;
            }
        }
    }
    printf("answer = %d\n",n);
    return 0;
}
Example #11
0
TEST(isPermutationTest, unPermutation){
    EXPECT_EQ(false, isPermutation( "He","eh"));
    EXPECT_EQ(false, isPermutation( "old","dog"));
}
Example #12
0
TEST(isPermutationTest, permutation){
    EXPECT_EQ(true, isPermutation("orchestra","carthorse"));
    EXPECT_EQ(true, isPermutation( "he is a coder","is he a coder"));
}
Example #13
0
bool OperateurCycle::backtrack(int v)
{
	bool f = false;
	point_stack.push(v);
	mark[v] = true;
	marked_stack.push(v);
	for(set<int>::iterator it = succ_num[v].begin();it!=succ_num[v].end();)
	{
		int w = *it;
		//cout<<w<<endl;
		if(w<s)
		{
			succ_num[v].erase(it++);
		}
		else
		{
			++it;
			if(w==s)
			{
				//cout<<"Circuit détecté"<<endl;//circuit
				stack<int> disp_stack = point_stack;
				vector<Noeud*> children;
				while(!disp_stack.empty())
				{
					//cout<<noeudsParNum[disp_stack.top()]->nom_parser<<"<-";
					children.push_back(noeudsParNum[disp_stack.top()]);
					disp_stack.pop();
				}
				if(children.size()>2) //on ne considère pas les cycles de taille 2
				{
					bool dejaVu = false;
					for(set<Noeud*>::iterator it = res.begin();it!=res.end();it++)
					{
					if(isPermutation((*it)->enfants,children))
					{
						dejaVu = true;
						break;
					}
					}
					if(!dejaVu)
					{
						NonTerminal* new_node = new NonTerminal(name,children);
						new_node->setAttribut("size",new AttributInt(children.size()));
						if(calculAtt!=NULL)
						{
							calculAtt->calculAttrib(new_node);
						}
						res.insert(new_node);
					}
					/*cout<<"Cycle :";
					for(vector<Noeud*>::iterator it = children.begin();it!=children.end();it++)
						cout<<(*it)->nom_parser<<" ";
					cout<<endl;*/
				}
				f=true;
			}
			else if(!mark[w])
			{
				bool g = backtrack(w);
				f =f ||g;
			}
		}
	}
	if(f)
	{
		while(marked_stack.top()!=v)
		{
			int u = marked_stack.top();
			marked_stack.pop();
			mark[u]=false;
		}
		marked_stack.pop();
		mark[v]=false;
	}
	point_stack.pop();
	return f;
}
void main(int argc, char * argv[]){
  isPermutation(argv[1], argv[2]) ? printf("true") : printf("false");
}