Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 8 of 8
  1. #1
    Regular Coder
    Join Date
    Nov 2002
    Location
    Carmel California
    Posts
    471
    Thanks
    0
    Thanked 1 Time in 1 Post

    text scramble scan through

    does anybody have a script that could take a word and create every posibility of combinations with it, here an example of what I might get from the function if I did it the word is cow
    cow
    cwo
    ocw
    owc
    wco
    woc

    this is not some homework cheating or something
    I am using this for a word de scrambler that uses a text file thats a spell cheqer word list ( previous post was about text file reading)

    so I could put in the string lheol and find hello

    I been trying about 3 hours to figure out how to make that pattern simple into javascript but I want to ask if anybody has one so I don't have to spend time thats already been spent.
    Kris Hubby
    kwhubby site

  • #2
    Regular Coder
    Join Date
    Jun 2002
    Location
    Montreal, Canada
    Posts
    644
    Thanks
    0
    Thanked 0 Times in 0 Posts

  • #3
    Regular Coder
    Join Date
    Nov 2002
    Location
    Carmel California
    Posts
    471
    Thanks
    0
    Thanked 1 Time in 1 Post
    grrrr, i see.... um I have a plan on how to do it, I already have the plan on how the pattern works, and how to make it in javascript. I just need to really do it. and i have most of it kindov done. all i need to do is write about 10 loops and about 10 if statements, not to mention the real work of really getting it to work without errors, or undesired operation.

    that post you gave didn't help much because the solution was not reached

    but hopefully i can figure it out with lots of work

    Ill post updates if i get anyfarther


    edit: although if nobody in this forum succeeded, Its pretty likely I wont succeed either
    Last edited by kwhubby; 02-23-2003 at 05:52 AM.
    Kris Hubby
    kwhubby site

  • #4
    Regular Coder
    Join Date
    Nov 2002
    Location
    Carmel California
    Posts
    471
    Thanks
    0
    Thanked 1 Time in 1 Post
    I made it! I actually did it, now all I have to do is... get it to work right!, this will take the longest because ive probobly really screwed it up with a lot of little mistakes when making this (im really sloppy when I script!).
    the script, (well not without error now) acomplishes this by first finding what position is ready to swap, it then swaps the position with the lowest original-position,-value-letter to the right of the position being changed, it then orders the ones to the now right of the position in numerical order
    so creating this patern with a 3 character word
    123
    132
    213
    231
    312
    321

    or this for a 4 letter word

    1234
    1243
    1324
    1342
    1423
    1432
    2134
    2143
    2314
    2341...... etc...
    Kris Hubby
    kwhubby site

  • #5
    Regular Coder
    Join Date
    Jun 2002
    Location
    Montreal, Canada
    Posts
    644
    Thanks
    0
    Thanked 0 Times in 0 Posts
    GOT IT!

    Code:
    <script>
    
    perm = new Array("a","b","c","d");
    
    // <-- CALCULATES NUMBER OF PERMUTATIONS -->
    perm_len = new Array("0");
    x = perm.length;
    z = 1;
    y = 1;
    while (z<=x) {
     y *= z;
     perm_len[z] = y;
     z++;
    }
    // <-- --> //
    
    // <-- GENERATES PERMUTATIONS -->
    perm_arr = new Array("",new Array(perm[0]));
    for (x=2; x<=perm.length; x++) {
     perm_arr[x] = new Array();
     for ( y in perm_arr[x-1] ) {
      for (z=0; z<=perm_arr[x-1][y].length; z++ ) {
       start = perm_arr[x-1][y].slice(0,z);
       end = perm_arr[x-1][y].slice(z,perm_arr[x-1][y].length);
       perm_arr[x][perm_arr[x].length] = start.concat(perm[x-1],end);
      }
     }
    }
    // <-- --> //
    
    
    document.write(perm); // print source array
    document.write("<br>");
    document.write(perm_len); // print permutations length array
    document.write("<br>");
    document.write(perm_arr[perm.length]); //print generated permutations array
    
    </script>
    Last edited by x_goose_x; 02-23-2003 at 06:59 PM.

  • #6
    Regular Coder
    Join Date
    Jun 2002
    Location
    Montreal, Canada
    Posts
    644
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Add:
    Code:
    // <-- REMOVES IDENTICAL INSTANCES --> \\
    for (x=0; x<perm.length; x++) {
     for (y=0; y<perm.length; y++) {
      if ( ( perm[x] == perm[y] ) && ( x != y ) ) {
       perm = perm.slice(0,y).concat(perm.slice(y+1,perm.length));
       x--;
      }
     }
    }
    // <-- --> //
    right after the line:

    perm = new Array("a","b","c","d");

    if you want it to remove items entered twice.

  • #7
    Regular Coder
    Join Date
    Nov 2002
    Location
    Carmel California
    Posts
    471
    Thanks
    0
    Thanked 1 Time in 1 Post
    ahh thanks, It work fine without the extra edition (I don't understand what you mean I don't get any problems like that. It goes in a different patern than mine, sortov but it works, so I think Ill adapt it to my needs, and use it.
    ITs funny, the script looks very similar to mine with the arrays, and multiple for loops, and such, but of course it works unlike mine at the moment.
    good job


    and thanks again
    Kris Hubby
    kwhubby site

  • #8
    Regular Coder
    Join Date
    Nov 2002
    Location
    Carmel California
    Posts
    471
    Thanks
    0
    Thanked 1 Time in 1 Post
    I adapted it to fill an array with the values it creates, instead of making that comma list thing

    edit: woops didn't see it was a 2d array lol
    Last edited by kwhubby; 02-23-2003 at 11:35 PM.
    Kris Hubby
    kwhubby site


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •