for(int A = 3; A<50;A++) for(int B = 2; B<A; B++) for(int C = 1; C<B; C++) for(int D = 0; D<C; D++){ // do something.. }
- Perhaps you should state what you're trying to do instead of asking for a less "stupid way to do something."
- Perhaps you should state what you're trying to do instead of asking for a less "stupid way to do something."
Hi WHRoeder,
Thanks for the reply. I'll think about it.
To answer to your suggestion, I'm trying to make all possible combinations of 8 items of 74 different items without using an item more than once in a single combination.
Forgot to mention, that the position of an item in a combination is not relevant.
Meaning if there is already a combination ABCD then DCBA should not be added...
- Combinations not permutations the code basically does like the diagram on Combination - Wikipedia, the free encyclopedia (Permutations means position is important.)
- 74 items taken 8 at a time is 11,969,016,300. (Permutations jumps to 482,590,739,000,000.)
- Let me guess - 74 different indicators as filters. The 8 is arbitrary. Try using bitmaps:
#define IND01 1 #define IND02 2 #define IND03 4 #define IND04 8 #define IND05 16 #define IND06 32 #define IND07 64 #define IND08 128 extern int bm1 = 255; // Tester start=0, step=1, max=255 #define IND09 1 #define IND10 2 #define IND11 4 #define IND12 8 #define IND13 16 #define IND14 32 #define IND15 64 #define IND16 128 extern int bm2 = 255; : bool useInd01(){ return(bm1 & IND01); // Bitwise and (not logical and) : bool useInd16(){ return(bm2 & IND16);
replace 01, 02, ... with meaningful names.
- Let me guess - 74 different indicators as filters. The 8 is arbitrary. Try using bitmaps:
replace 01, 02, ... with meaningful names.
Spot on. Though not all indicators can work together. See it as a list of restrictions:
use indi7 only if indi1 is already in the combination
don't use indi8 if indi4 is already in the combination
Would bitmaps still be a good solution? If yes I'll study it - know nothing about it atm.
Thanks for your help!
bool useInd07(){ return(bm1 & IND07 != 0 && useInd01() ); // use indi7 only if indi1 is already in the combination bool useInd08(){ return(bm1 & IND08 != 0 && !useInd04() ); // don't use indi8 if indi4 is already in the combination
So I've been trying to get the hang of working with bitmaps.
#define IND01 1 #define IND02 2 #define IND03 4 #define IND04 8 #define IND05 16 #define IND06 32 #define IND07 64 #define IND08 128 extern int bm1 = 255; // Tester start=0, step=1, max=255 #define IND09 1 #define IND10 2 #define IND11 4 #define IND12 8 #define IND13 16 #define IND14 32 #define IND15 64 #define IND16 128 extern int bm2 = 255; : bool useInd01(){ return(bm1 & IND01); // Bitwise and (not logical and) : bool useInd16(){ return(bm2 & IND16);
In this example I don't see how a function like useInd01 can return different values ? I also don't see what bm1 and bm2 are doing. So I tried to make an easy example to test things out:
#define IND01 1 #define IND02 2 #define IND03 4 #define IND04 8 #define IND05 16 int init() { start(); return(0); } int deinit() { return(0); } int start() { string CMNT = ""; for(int X=0; X<32;X++){ CMNT = CMNT + "\n Combi "+X+" = "+useInd01(X)+" "+useInd02(X)+" "+useInd03(X)+" "+useInd04(X)+" "+useInd05(X); } Comment(CMNT); return(0); } bool useInd01(int CC){ return(CC & IND01); } bool useInd02(int CC){ return(CC & IND02); } bool useInd03(int CC){ return(CC & IND03); } bool useInd04(int CC){ return(CC & IND04); } bool useInd05(int CC){ return(CC & IND05); }
This does seem to make different combinations although I don't really understand what I'm doing (I'm just trying things out). On the chart you get different combinations printed with values on each of the 5 entries. So I could take 0 = off and != 0 is on and then I can use it to determine at which combination which indicator should be used.
Could someone explain the differences between the two structures above?
extern int bm1 = 255; // Tester start=0, step=1, max=255In this example I don't see how a function like useInd01 can return different values ? I also don't see what bm1 and bm2 are doing.

- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Hello,
Could someone suggest me a better way of doing this:
Cause I think this is the stupid way to do something which can be done in a better way..
Thanks!