I'm currently trying to program that finds the number of triplets of a number from
6-12345 and also shows the best set of triplets and processing speed for the program.
Best set means the diff between largest and smallest number is minimal.
E.g input number in data8.txt(file that the number is extracted from): 9
Output ---> Number of triplets:3
Best triplet: 3 4 5
Processing time in sec: 0
My teacher already gave some guidelines like how to show the processing speed,
(int t = time(0);) and (cout << "Processing time in Sec: " << time(0) - t << endl;)
I would prefer to use switch to lower the processing time but I do not understand what to program in the cases. Need some advice!
I am not sure I am following the problem at all.
Are you looking for 3 numbers in a row? What is a triplet here?
if so, why not loop like this...
for(I = 4; I < size-2; I++)
{
if( I ? I+1 ? I+2) //some condition that looks at 3 consecutive values
then hooray, you found one, count it, save it, is it the best??
}
Sorry did not make myself clear, 'triplet' means a set of three numbers that add up to the number extracted from 'data8.txt'. As seen in the example, 3+4+5=9. Another triplet can also be 1+2+6. A number cannot be duplicated. So, best triplet means that the difference between the largest and smallest number in that particular triplet is the smallest out of all possible triplets. For example, the difference between 3 and 5 is the smallest possible, 2 as there must be 3 different numbers. Compared to the difference between 1 and 6, it is smaller.
Hope this clarifies your confusions with my questions. Any other advice?
you only have to check 1/2 the numbers, by the way
if the input is 9, if you code it right, the third number (even if larger than 50% of 9) will already have been found.
choose 1, ok, 9-1 is 8.
choose 2, ok, 8-2 is 6.
the third # is 6.
It isn't possible to have 3 values with 2 of them larger than 50% of the input value that add up to the input value.
I am not sure a switch is the answer. Conditionals, nested loops, etc all break the u-v pipeline. But we can check to see. Do the values need to be unique? Or is 2+2+2 ok for 6?
There MAY be a direct computation for the # of triplets... it looks like the sort of thing that might...