
'Combinational' Code Required
Hi!<BR><BR>In my current ASP project, I have a task of generating all the possible combinations of some supplied strings e.g If ABC is given, I must have<BR><BR>A<BR>B<BR>C<BR>AB<BR>BC<BR>AC<BR><BR>S ome help in code regarding this matter. I'll be supplying a much larger string actually e.g 30 digitd or 50 digits. But time is not a factor for me.<BR><BR>Any URLs, Any Help Articles or code samples are most welcome.<BR><BR>Thanx in anticipation.

Heres one I prepared earlier...
Hope it works with letters...<BR><BR><% <BR>' This array contains the numbers you wish to get the combinations of: <BR>NumAry = Array("A","B","C") <BR><BR>For i=1 To 2^(UBound(NumAry)+1)1 <BR> For ix=0 To Ubound(NumAry) <BR> BinaryValue = 2^ix <BR> If i AND BinaryValue Then <BR> AddString = AddString & NumAry(ix) & "+" <BR> End If <BR> Next <BR> Response.write Left(AddString,Len(AddString)1) & "< br>" <BR> AddString = "" <BR>Next <BR>%>

RE: 'Combinational' Code Required
1) This isn't easy<BR>2) You have to have a sound understanding of mathematics. You have to know, for instance, that 3 letters have 15 possible combinations, not the 6 you listed above. <BR><BR>3) Every time someone has needed help with this, their endresult could always be accomplished an easier way. This is hardly ever needed. *PLEASE* share what you're actually trying to accomplish. <BR><BR>Shane

Nope
Your code returns:<BR><BR>A<BR>B<BR>A+B<BR>C<BR>A+C<BR>B+C<B R>A+B+C<BR><BR>The possible combinations for A, B, C are:<BR><BR>A<BR>AB<BR>ABC<BR>AC<BR>ACB<BR>B<BR>BA <BR>BAC<BR>BC<BR>BCA<BR>C<BR>CA<BR>CAB<BR>CB<BR>CB A

But I can see..
that it does work for numbers...<BR><BR>1+2 is the same as 2+1 ... but you can't use that logic for letters.

RE: Nope
Yes U R right actually I forgot to right etc etc etc at the end of the six combinations I made..<BR><BR><BR>:))

RE: 'Combinational' Code Required
My application is a Mathematics based demo for children in which I want to explain how combinations are made.<BR><BR>About my maths skills don't worry, I am a Graduate.<BR><BR>

Could be adapted...
You'd need (another!) loop outside the current ones which shifted all the characters in the array to the right on each iteration until each was done.<BR><BR>ary = ("a","b","c")<BR>' loop existing code<BR><BR>ary = ("c","a","b")<BR>' loop existing code<BR><BR>ary = ("b","c","a")<BR>' loop existing code<BR><BR>Hmm, would that work ? need to think about it a bit more maybe.<BR><BR>

You ****DONT**** Want to do this
If you are a "graduate" then you understand there must be a better way. <BR><BR>If you seriously want all the combinations of a 30 digit number, prepare to wait a long time for the results and understand that you'll probably crash the browser. <BR><BR>Even if you only want all the possible 30 digit combinations made from that number, you're looking for 30! Which is <BR><BR>2.6525285981219105863630848e+32<BR><BR>I don't think that would much help to the children. Plus, if you want to include combinations of lesser length (combinations between 1 and 29 letters long) then you're talking about millions more. <BR><BR>Like I said, you don't want to do this.

RE: Could be adapted...
Seems it will work but how to define arrays dynamically, the string is not always a, b and c<BR><BR>can we do it like <BR><BR>array(left(OurString,1),right(OurString,1) ) {Just for example something like this???}
Posting Permissions
 You may not post new threads
 You may not post replies
 You may not post attachments
 You may not edit your posts

Forum Rules

