473,320 Members | 1,817 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Possibility List Calculation

Hi Guys,

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:
  1. S
  2. M
  3. 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:
  1. SSSS
  2. SSSM
  3. SSST
  4. SSMM
  5. SSMT
  6. SSTT
  7. SSTM
  8. SMMM
  9. SMMT
  10. SMTT
  11. STTT
  12. MMMM
  13. MMMT
  14. MMTT
  15. MTTT
  16. 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:
  1. SSSS
  2. SSSM
  3. SSST
  4. SSM
  5. SST
  6. SM
  7. ST
  8. MMMM
  9. MMMT
  10. MMT
  11. MT
  12. 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
  1.  
  2.   Loop MinorLoop1# = 1 to Records(MinorListQ) 
  3.  
  4.     Number# = DMA:ActiveGenes 
  5.  
  6.     clear(MinorListQ)
  7.     MLQ:Number = MinorLoop1# 
  8.     get(MinorListQ,MLQ:Number)
  9.     if error(); message(error()).
  10.  
  11.     clear(GeneticQ)    
  12.     loop Loop1# = 1 to Number#
  13.       QGE:ActiveGenes = clip(QGE:ActiveGenes)&''&clip(MLQ:Gene)
  14.     end
  15.  
  16.     add(GeneticQ)
  17.  
  18.     loop 
  19.       Number# -= 1
  20.       if Number# <= 0; break.
  21.  
  22.       MinorLoop2# = (MinorLoop1# + 1)
  23.  
  24.       clear(MinorListQ)
  25.       MLQ:Number = MinorLoop1#
  26.       get(MinorListQ,MLQ:Number)
  27.       if error(); message(error()).
  28.  
  29.       clear(GeneticQ)
  30.  
  31.       clear(AGenes)
  32.  
  33.       loop Loop1# = 1 to Number#
  34.         AGenes = clip(AGenes)&''&clip(MLQ:Gene)
  35.       end
  36.  
  37.       loop Loop2# = MinorLoop2# to DMA:ActiveGenes 
  38.         clear(MinorListQ)
  39.         MLQ:Number = Loop2#
  40.         get(MinorListQ,MLQ:Number)
  41.         if error(); message(error()).
  42.         QGE:ActiveGenes = clip(AGenes)&''&clip(MLQ:Gene)
  43.         add(GeneticQ)
  44.       end  
  45.     end
  46.   end
  47.  

Sorry for the long post. All suggestions and ideas are welcomed.
May 1 '12 #1

✓ answered by Rabbit

You could do something like this:
Expand|Select|Wrap|Line Numbers
  1. for a = 1 to 3
  2.    for b = a to 3
  3.       for c = b to 3
  4.          for d = c to 3
  5.             print a & b & c & d
  6.          end for
  7.       end for
  8.    end for
  9. end for

6 1921
Rabbit
12,516 Expert Mod 8TB
You could do something like this:
Expand|Select|Wrap|Line Numbers
  1. for a = 1 to 3
  2.    for b = a to 3
  3.       for c = b to 3
  4.          for d = c to 3
  5.             print a & b & c & d
  6.          end for
  7.       end for
  8.    end for
  9. end for
May 1 '12 #2
Rabbit
12,516 Expert Mod 8TB
By the way, result 7 in your post is wrong. It shouldn't be there. And for future reference, the concept is called a Combination with Repetition.
May 4 '12 #3
Thanks for pointing me in the right direction I was searching up possibility instead of combination formulas. When you say result 7 did you mean the first 7 (SSTM) or the second 7 (ST). I don't see what is wrong with either of them. Could you please explain.
May 5 '12 #4
Rabbit
12,516 Expert Mod 8TB
Number 5 is SSMT and number 7 is SSTM. It's a repeat, one of them needs to go. I say number 7 because it doesn't follow the established pattern.
May 5 '12 #5
Oh... yes I see what you mean. Good spotting. Thank you a lot for your responses and the time you've spent to help answer my question. I've been able to make some headway and should be able to work out the final pieces to the puzzle now.
May 6 '12 #6
Rabbit
12,516 Expert Mod 8TB
Good luck. Let us know how you get along.
May 6 '12 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

7
by: Vinoth | last post by:
I'm working in an ARM (ARM9) system which does not have Floating point co-processor or Floating point libraries. But it does support long long int (64 bits). Can you provide some link that would...
9
by: falcon | last post by:
Is there a way I can do time series calculation, such as a moving average in list comprehension syntax? I'm new to python but it looks like list comprehension's 'head' can only work at a value at...
10
by: Ben | last post by:
Hello... I have set up a dictionary into whose values I am putting a list. I loop around and around filling my list each time with new values, then dumping this list into the dictionary. Or so I...
6
by: Osiris | last post by:
Is the following intuitively feasible in Python: I have an array (I come from C) of identical objects, called sections. These sections have some feature, say a length, measured in mm, which is...
13
by: Maria Mela | last post by:
Hello everyone... Anybody can help me on this question, please? i´ve this code in my application: /*for Card creation*/ typedef struct card { etc,etc } Card; typedef Card *PtrCrt;
5
by: The alMIGHTY N | last post by:
Hi all, Let's say I have a simple math formula: sum (x * y / 1000) / (sum z / 1000) I have to do this across 50 items, each with an x, y and z value, when the page first loads AND when a...
1
by: PeterdeHoogh | last post by:
Hi, I'm new to Access and want to write a small programme for the administration of a family confection business. For that I want to use a form in which I can easily access the order information for...
49
by: seema | last post by:
Hi all, How to calculate upper 4 bytes and lower 4 bytes of a value? Can somebody please explain?? say for example, unsigned int scnlen_lo; int scnlen_hi; unsigned long long scnlen; ...
3
by: Amit | last post by:
Hello Gurus, I am very new to .net . My application is calculating values on run time ,and after all the calculation , i want to print all calculation as a report to show it to user. please...
2
by: aboxylica | last post by:
I have a file like this!Sequence Header: >Sbay YOR009W c606:3651..4650 Sequence = CCTAATCTTGAAAAAA Calculation = 1 Sequence = CTAATCTTGAAAAAAA Calculation = 1 Sequence = TAATCTTGAAAAAAAA...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.