-
Combinations
Hi!
Let's say we have 200 combinations. Now I want to write a program, that will search for those combinations and that will never find two the same combinations, always different. How to do that? Should I search for those combinations in some order?
If you have an idea, don't hesitate and write it down.
Thank you in advance.
-
I do not quite understand what combinations you're talking about.
A combination of 200 digits? A combination of 200 bits? A combination of 2 numbers each running from 1 to 200?
-
Actually, the bruteforce approach, to search n number of combinations is simply indexing by one.
If you have 200 combinations, then start with the first:
000
and increment by one
001
002
003
...
until you reach:
200
---
enjoy.
-
I have 12 files and every file has 50 lines. Now I want that from each file the program will select the first line and then in the second file the second line and so on. I want to generate all combinations.
Example:
first file: first line, second file: first line, ..., and then all over again first line: second line, second file: first line, ...
How to do that?
-
Hi!
I just can say that there are 25^12 possibilities.
klausi
-
Code:
#include <stdio.h>
int main (void)
{
int i[3];
for (i[0] = 0; i[0] < 6; i[0]++)
for (i[1] = 0; i[1] < 6; i[1]++)
for (i[2] = 0; i[2] < 6; i[2]++)
{
printf ("%d %d %d\n", i[0], i[1]. i[2]);
}
return 0;
}
Hope that helps, although in the file example you describe.... well, it looks like you want to process every line in every file, which makes me wonder, why not just process the whole files at once? Could you decribe a bit more what you want to do?
-
I have some text in those 12 files. Which file contains 50 lines of text. Now I want to generate all combinations (i think that the number of all combinations is 12^50, is that right?). From each file i select one line and copy it to the other file (in that file i get then 12 lines). I want to generate all combinations.
QuestionC: please explain a bit more your code. What is that "i" and that 6 (number of files?) in the for loop?
-
/* With 12 files of 50 lines, you get 50^12 texts */
/* Code for 3 files of 5 lines each.
You get 5^3 = 125 different texts" */
#include <stdio.h>
int main(void)
{
int i, j, k, count;
char text1[5][12]={ "text1 line1", "text1 line2", "text1 line3", "text1 line4", "text1 line5"};
char text2[5][12]={ "text2 line1", "text2 line2", "text2 line3", "text2 line4", "text2 line5"};
char text3[5][12]={ "text3 line1", "text3 line2", "text3 line3", "text3 line4", "text3 line5"};
count = 1;
for(i=0;i<5;i++)
for(j=0;j<5;j++)
for(k=0;k<5;k++){
printf("text number %d\n",count++);
printf("%s\n",text1[i]);
printf("%s\n",text2[j]);
printf("%s\n",text3[k]);
printf("\n\n");}
return 0;
}
-
Unregistered:
You print this to the screen. How to do it that the program will append text from each line into a string?
Example:
string[1000];
now I want that the string will be something like that:
text1 line1
text2 line1
text3 line1
and then the program must clear the string and appends another combination:
text1 line1
text2 line2
text3 line2
and so on. How to do that?
-
for(i=0;i<5;i++)
for(j=0;j<5;j++)
for(k=0;k<5;k++)
{
sprintf(texte, "%s\n%s\n%s\n",text1[i],text1[j],text1[k]);
printf("%s\n",texte);
getc(stdin);
}
-
Sorry, it's
sprintf(texte, "%s\n%s\n%s\n",text1[i],text2[j],text3[k]);
of course ...
-
Thanks GertFaller, but I already figure it out yesterday. Now I want to know does sprintf automatically adds '\0' to the end of the whole string?
-
-
-
Itīs right that there are 50^12 possible combinations, but if you wanna compare them, there are only 25^12.
klausi