...

View Full Version : text scramble scan through



kwhubby
02-22-2003, 08:05 AM
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.

x_goose_x
02-23-2003, 05:55 AM
http://www.codingforums.com/showthread.php?s=&threadid=9993

kwhubby
02-23-2003, 06:47 AM
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 :o

kwhubby
02-23-2003, 09:58 AM
:) 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...

x_goose_x
02-23-2003, 07:47 PM
GOT IT!



<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>

x_goose_x
02-23-2003, 07:57 PM
Add:


// <-- 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.

kwhubby
02-23-2003, 11:51 PM
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
:thumbsup:

and thanks again :D

kwhubby
02-24-2003, 12:14 AM
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:o



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum