Copy link to clipboard
Copied
How could I loop through all possible rearrangement combinations of these 8 characters? LLLMMRRR
I need it to be output with trace command and numbered if possible.
Copy link to clipboard
Copied
is each L a different character? ie, if you only had LLL would there be one or 6 displays?
Copy link to clipboard
Copied
I have 3 L's 2 M's and 3 R's in one arrangement like the one you see above. I want them to be rearranged in deferent order and I need to see all possible combination in the output through trace command.
Copy link to clipboard
Copied
again, are different combinations that look the same, different? if so, you'll see LLLMMRRR listed 72 times.
Copy link to clipboard
Copied
I want to output all possible combination since I have to go through each one by one.
Copy link to clipboard
Copied
var i:int;
var s:String = 'LLLMMRRR';
var permA:Array = [];
permF(s,'');
trace(permA);
function permF(s: String, pre: String): void {
if(s.length < 1){
permA.push(pre);
} else {
for(i = 0; i < s.length; i++){
permF(s.substr(0, i) + s.substr(i + 1), pre + s.charAt(i));
}
}
}
p.s. if you want combinations (i never got an answer from you that i could understand), sort permA and loop through its elements checking for duplicates:
function removeDupsF(a:Array):Array{
a.sort();
for(var j:int=a.length-1;j>0;j--){
if(a
a.splice(j,1);
}
}
return a;
}
Copy link to clipboard
Copied
I only get one output LLLMMRRR
Copy link to clipboard
Copied
that's interesting. the problem is i.
use:
//var i:int; // commented out
var s:String = 'LLLMMRRR';
var permA:Array = [];
permF(s,'');
trace(permA);
function permF(s: String, pre: String): void {
if(s.length < 1){
permA.push(pre);
} else {
for(var i:int = 0; i < s.length; i++){ // <-i is local of permF and retains its value during during function calls
permF(s.substr(0, i) + s.substr(i + 1), pre + s.charAt(i));
}
}
}
and please mark correct and helpful responses. i see you still have not done that in your collision thread.
Copy link to clipboard
Copied
This one worked...ish, I got all the possible combinations (I think) but
they were multiplied by 72. so I got 72 LLLMMRRR and then I got
72 LLLMRMRR... and so on and so forth.