I think which each combination being completely unique, i have no other
option than a honkin' switch or if/else. Lots of typing but will work. I can
work on making it more readable, but thats about it methinks.

On 1/25/06, Andreas Weber <[EMAIL PROTECTED]> wrote:
>
> 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
>
_______________________________________________
Flashcoders mailing list
Flashcoders@chattyfig.figleaf.com
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Reply via email to