I've been working on this project for a couple days now and i can't figure out how to make the program exhaust(brute force) through all the possibilities. The aim of the project is to read 3 words whose have up to 10 unique letters and find out what each letter equals. So far i am able to read words and store them and check for all the letters that dont repeat, i can also assign numbers but am not able to exhaust all paussible permutations i can only assign each letter a number once.

I am using send+more=money as base so my output is:

unique letters=sendmory

and the values assigned are:

send

1234

more

5672

money

56328

Any help or ideas to get me going would be greatly appreciated.

Code:#include <stdio.h> #include <ctype.h> #include <math.h> #define N 10 long int assignv1(char uletter[], int nletter, int value[], char word1[], int nword1); long int assignv2(char uletter[], int nletter, int value[], char word2[], int nword2); long int assignv3(char uletter[], int nletter, int value[], char word3[], int nword3); int main(void) { char word1[N], word2[N], word3[N],uletter[N]; int nword1, nword2, nword3,nletter,nuletter, value[N]; //counter of letters in words int i,j=0, k, l,flag;d long int value1=0,value2=0,value3=0; printf("Please input the first in capital letters\n"); for(i=0;i<N;i++) { word1[i]=getchar(); if(word1[i]=='\n') break; } nword1=i; printf("Please input the first in capital letters\n"); for(i=0;i<N;i++) { word2[i]=getchar(); if(word2[i]=='\n') break; } nword2=i; printf("Please input the first in capital letters\n"); for(i=0;i<N;i++) { word3[i]=getchar(); if(word3[i]=='\n') break; } nword3=i; nletter=nword1+nword2+nword3; /*_______________________________________________________________________*/ //count unique letters uletter[0]=word1[0]; nuletter=1; for(i=1;i<nword1;i++) { flag=0; for(j=0;j<nuletter;j++) { if(word1[i]==uletter[j]) flag=1; } if(flag==0) { uletter[nuletter]=word1[i]; nuletter++; } } for(i=0;i<nword2;i++) { flag=0; for(j=0;j<nuletter;j++) { if(word2[i]==uletter[j]) flag=1; } if(flag==0) { uletter[nuletter]=word2[i]; nuletter++; } } for(i=0;i<nword3;i++) { flag=0; for(j=0;j<nuletter;j++) { if(word3[i]==uletter[j]) flag=1; } if(flag==0) { uletter[nuletter]=word3[i]; nuletter++; } } printf("number of letters=%i\n",nletter); printf("number of unique letters=%i\n",nuletter); for(i=0;i<nuletter;i++) printf("%c\n",uletter[i]); /*_______________________________________________________________________*/ j=0; for(i=0;i<N;i++) { j++; value[i]=j; } value[9]=0; for(k=0;k<N;k++) { i++; j++; value1=assignv1(uletter, nletter, value, word1, nword1); value2=assignv2(uletter, nletter, value, word2, nword2); value3=assignv2(uletter, nletter, value, word3, nword3); if (value1+value2==value3) { printf("%li\n",value1); printf("%li\n",value2); printf("%li\n",value3); } } return 0; } long int assignv1(char uletter[], int nletter, int value[], char word1[], int nword1) { int i,j; long int value1=0; for(i=0;i<nword1;i++) { for(j=0;j<nletter;j++) { if(word1[i]==uletter[j]) //Inputing value to unique letter { value1+=value[j]*pow(10, (nword1-i-1)); } } } return value1; } long int assignv2(char uletter[], int nletter, int value[], char word2[], int nword2) { int i,j; long int value2=0; for(i=0;i<nword2;i++) { for(j=0;j<nletter;j++) { if(word2[i]==uletter[j]) //Inputing value to unique letter { value2+=value[j]*pow(10, (nword2-i-1)); } } } return value2; } long int assignv3(char uletter[], int nletter, int value[], char word3[], int nword3) { int i,j; long int value3=0; for(i=0;i<nword3;i++) { for(j=0;j<nletter;j++) { if(word3[i]==uletter[j]) //Inputing value to unique letter { value3+=value[j]*pow(10, (nword3-i-1)); } } } return value3; }