• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Loop 8 characters

Participant ,
Aug 27, 2015 Aug 27, 2015

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.

TOPICS
ActionScript

Views

334

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Aug 27, 2015 Aug 27, 2015

Copy link to clipboard

Copied

is each L a different character?  ie, if you only had LLL would there be one or 6 displays?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Aug 27, 2015 Aug 27, 2015

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Aug 27, 2015 Aug 27, 2015

Copy link to clipboard

Copied

again, are different combinations that look the same, different?  if so, you'll see LLLMMRRR listed 72 times.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Aug 27, 2015 Aug 27, 2015

Copy link to clipboard

Copied

I want to output all possible combination since I have to go through each one by one.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Aug 27, 2015 Aug 27, 2015

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[j-1]){

            a.splice(j,1);

        }

    }

    return a;

}

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Aug 27, 2015 Aug 27, 2015

Copy link to clipboard

Copied

I only get one output LLLMMRRR

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Aug 27, 2015 Aug 27, 2015

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Aug 28, 2015 Aug 28, 2015

Copy link to clipboard

Copied

LATEST

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines