I've got this unique situation that I've never come across before. What I want to do is create a piece of code that will add to a list all the possibilities based off of settings that have been set.
What I currently have is a list of possible entries that looks somthing like this:
- S
- M
- T
I also have an entry in the program where the user defines how many spaces there can be. For this example I'll use 4.
What I want to be able to do is generate a list of all possible combinations bassed of of the number of entries in the list (the user has the ability to add or remove entries whenever they want) and the number of places that they enter.
For the example information I have provided I want the list to show:
- SSSS
- SSSM
- SSST
- SSMM
- SSMT
- SSTT
- SSTM
- SMMM
- SMMT
- SMTT
- STTT
- MMMM
- MMMT
- MMTT
- MTTT
- TTTT
I'm just not sure how to achieve this. I realise that I will need some sort of complex looping code to achieve this. Any suggestions or ideas on how to achieve this would be greatly appreciated. I have the details of what I currently am able to achieve below. I am using the programming language Clarion but I can also understand Visual Basic and JavaScript.
The problem is that I can get the list to show:
- SSSS
- SSSM
- SSST
- SSM
- SST
- SM
- ST
- MMMM
- MMMT
- MMT
- MT
- TTTT
Using the code below where the MinorListQ is the list containing the first list I've got above with the values of S, M, and T in it and the GeneticQ is the list I'm creating with all the probable values in it (the third list). The DMA:ActiveGenes contains the number 4 in the example I have given and anything with a # after it is a local variable that I've defined on the fly.
Again I'm not sure if this code is useful to anyone I just need ideas on how to achieve this.
Expand|Select|Wrap|Line Numbers
- Loop MinorLoop1# = 1 to Records(MinorListQ)
- Number# = DMA:ActiveGenes
- clear(MinorListQ)
- MLQ:Number = MinorLoop1#
- get(MinorListQ,MLQ:Number)
- if error(); message(error()).
- clear(GeneticQ)
- loop Loop1# = 1 to Number#
- QGE:ActiveGenes = clip(QGE:ActiveGenes)&''&clip(MLQ:Gene)
- end
- add(GeneticQ)
- loop
- Number# -= 1
- if Number# <= 0; break.
- MinorLoop2# = (MinorLoop1# + 1)
- clear(MinorListQ)
- MLQ:Number = MinorLoop1#
- get(MinorListQ,MLQ:Number)
- if error(); message(error()).
- clear(GeneticQ)
- clear(AGenes)
- loop Loop1# = 1 to Number#
- AGenes = clip(AGenes)&''&clip(MLQ:Gene)
- end
- loop Loop2# = MinorLoop2# to DMA:ActiveGenes
- clear(MinorListQ)
- MLQ:Number = Loop2#
- get(MinorListQ,MLQ:Number)
- if error(); message(error()).
- QGE:ActiveGenes = clip(AGenes)&''&clip(MLQ:Gene)
- add(GeneticQ)
- end
- end
- end
Sorry for the long post. All suggestions and ideas are welcomed.