I guess a switch is a little nicer to look at.
On 1/25/06, Merrill, Jason <[EMAIL PROTECTED]> wrote: > > Well, if only 16 possibilities, then just use a switch statement (not an > if-else - too hairy IMO) > > Jason Merrill | E-Learning Solutions | icfconsulting.com > > > > > > > > > > > >>-----Original Message----- > >>From: [EMAIL PROTECTED] [mailto:flashcoders- > >>[EMAIL PROTECTED] On Behalf Of eric dolecki > >>Sent: Wednesday, January 25, 2006 2:50 PM > >>To: Flashcoders mailing list > >>Subject: Re: [Flashcoders] checking combinations > >> > >>dab, abd, adb, bda, dba, ... all the same combination. > >> > >>On 1/25/06, Merrill, Jason <[EMAIL PROTECTED]> wrote: > >>> > >>> Aren't there 256 possible combinations? Or if one value can be > null, > >>> then 625? What about dab, cab, bac, da, ca, etc? Or are you saying > for > >>> the sake simplicity, cab is the same combination as abc and dab the > same > >>> as abd? > >>> > >>> Jason Merrill | E-Learning Solutions | icfconsulting.com > >>> > >>> > >>> > >>> > >>> > >>> > >>> > >>> > >>> > >>> > >>> >>-----Original Message----- > >>> >>From: [EMAIL PROTECTED] > [mailto:flashcoders- > >>> >>[EMAIL PROTECTED] On Behalf Of Andreas Weber > >>> >>Sent: Wednesday, January 25, 2006 2:21 PM > >>> >>To: Flashcoders mailing list > >>> >>Subject: RE: [Flashcoders] checking combinations > >>> >> > >>> >>Seems to be an ispiring question/problem! > >>> >> > >>> >>Eric - if you'd go with the combo - Strings - these are the 16 > >>> possible > >>> >>combinations: > >>> >> > >>> >> ,a,ab,abc,abcd,abd,ac,acd,ad,b,bc,bcd,bd,c,cd,d > >>> >> > >>> >>(first one is an empty string if a && b && c && d are false) > >>> >> > >>> >>I'm not overly proud of how I found the combinations, but > sometimes > >>> nothing > >>> >>beats brute force :-) > >>> >> > >>> >> > >>> >>arr = ['a','b','c','d']; > >>> >>numElems = arr.length; > >>> >> > >>> >>combos = new Array(); > >>> >> > >>> >>c=0; > >>> >>while(c<100000){ > >>> >> combo = ''; > >>> >> for(var i=0; i<numElems; i++){ > >>> >> if(Math.random() < 0.5){ > >>> >> combo += arr[i]; > >>> >> } > >>> >> } > >>> >> inArray = false; > >>> >> for(var i=0, len=combos.length; i<len; i++){ > >>> >> if(combo == combos[i]){ > >>> >> inArray = true; > >>> >> break > >>> >> } > >>> >> } > >>> >> if(!inArray){ > >>> >> combos.push(combo); > >>> >> } > >>> >> > >>> >> c++; > >>> >>} > >>> >>combos.sort(); > >>> >>trace(combos); > >>> >>trace(combos.length); > >>> >> > >>> >> > >>> >>-------------- > >>> >>Andreas Weber > >>> >>motiondraw.com > >>> >> > >>> >> > >>> >> > >>> >>-----Original Message----- > >>> >>From: [EMAIL PROTECTED] > >>> >>[mailto:[EMAIL PROTECTED] Behalf Of > Martin > >>> >>Wood > >>> >>Sent: Wednesday, January 25, 2006 8:05 PM > >>> >>To: Flashcoders mailing list > >>> >>Subject: Re: [Flashcoders] checking combinations > >>> >> > >>> >> > >>> >>i've got to go out now so cant give the full answer i have in my > head, > >>> >>but one way of tackling it is to make each state variable's value > a > >>> >>power of 2 > >>> >> > >>> >>a = 1 > >>> >>b = 2 > >>> >>c = 4 > >>> >>d = 8 > >>> >> > >>> >>then you know that any combination of them has a unique value. > (its > >>> >>basically a 4 bit number) > >>> >> > >>> >>then to handle the dispatch depending on the state combination you > can > >>> >>build a function table. > >>> >> > >>> >>functionTable = new Array(); > >>> >> > >>> >>// create a handler for the combination a + b > >>> >>functionTable[a + b] = Delegate.create(this,combinationAB); > >>> >> > >>> >>and when you check the variables just call the function directly > from > >>> >>the table : > >>> >> > >>> >>// a,b,c,d are just passed as boolean flags here > >>> >>function handleUpdate(a:boolean,b:boolean,c:boolean,d:boolean) > >>> >>{ > >>> >> // taking advantage of a true being 1 in flash > >>> >> // and ideally you would setup these numbers > >>> >> // as static class variables > >>> >> var state = a + (b * 2) + (c * 4) + (d * 8); > >>> >> > >>> >> // call the defined function > >>> >> functionTable[state](); > >>> >>} > >>> >> > >>> >>of course you could do a check first to see if the function is > defined > >>> >>and do something like log a warning or whatever is appropriate for > >>> your > >>> >>situation. > >>> >> > >>> >>hope that makes sense. > >>> >> > >>> >>martin > >>> >> > >>> >> > >>> >>_______________________________________________ > >>> >>Flashcoders mailing list > >>> >>Flashcoders@chattyfig.figleaf.com > >>> >>http://chattyfig.figleaf.com/mailman/listinfo/flashcoders > >>> NOTICE: > >>> This message is for the designated recipient only and may contain > >>> privileged or confidential information. If you have received it in > error, > >>> please notify the sender immediately and delete the original. Any > other use > >>> of this e-mail by you is prohibited. > >>> _______________________________________________ > >>> Flashcoders mailing list > >>> Flashcoders@chattyfig.figleaf.com > >>> http://chattyfig.figleaf.com/mailman/listinfo/flashcoders > >>> > >>_______________________________________________ > >>Flashcoders mailing list > >>Flashcoders@chattyfig.figleaf.com > >>http://chattyfig.figleaf.com/mailman/listinfo/flashcoders > _______________________________________________ > Flashcoders mailing list > Flashcoders@chattyfig.figleaf.com > http://chattyfig.figleaf.com/mailman/listinfo/flashcoders > _______________________________________________ Flashcoders mailing list Flashcoders@chattyfig.figleaf.com http://chattyfig.figleaf.com/mailman/listinfo/flashcoders