...

View Full Version : Word Shuffle Software



srule_
03-15-2008, 01:55 PM
Hey, Is their any software or will this be easy to make with php?

What I want:
I have to list of words, for this example lets says "buy words" and "Food" words.

Buy words: Buy, Purchase
Food Words: Food, Grub

Now I need a program where I can enter each separate list and It gives me all the combinations like such:

Buy Food, Buy Grub, Purchase Food, Purchase Grub.

binaryWeapon
03-16-2008, 12:14 AM
Here's the function that you want in javascript. In the next few minutes I'll convert it to php, since you mentioned that, and post that as well.

var list1=new Array('wordA','wordB','wordC','wordD');
var list2=new Array('word1','word2','word3');
var combos="";

function combinations(array1, array2)
{
for(x=0; x<array1.length; x++)
{
for(y=0; y<array2.length; y++)
{
combos+=array1[x]+' '+array2[y]+', ';
}
}

for(a=0; a<array2.length; a++)
{
for(b=0; b<array1.length; b++)
{
combos+=array2[a]+' '+array1[b]+', ';
}
}
return combos;
}



$list1=array('wordA','wordB','wordC','wordD');
$list2=array('word1','word2','word3');
$combos="";

function combinations($array1, $array2)
{
$array1len=count($array1);
$array2len=count($array2);
for($x=0; $x<$array1len; $x++)
{
for($y=0; $y<$array2len; $y++)
{
$combos.=$array1[$x].' '.$array2[$y].', ';
}
}

for($a=0; $a<$array1len; $a++)
{
for($b=0; $b<$array2len; $b++)
{
$combos.=$array1[$a].' '.$array2[$b].', ';
}
}
return $combos;
} I also updated the JS version to use a return.

srule_
03-16-2008, 05:27 AM
Hey, Thanks alot! Only problem is it outputs results twice. using my example above it out puts "Buy Food, Buy Grub, Purchase Food, Purchase Grub, Buy Food, Buy Grub, Purchase Food, Purchase Grub"

instead of just "Buy Food, Buy Grub, Purchase Food, Purchase Grub"

whizard
03-17-2008, 12:21 AM
You could store each result in an array and check each time you get a new result to see if it is in the array. If it is, throw it away.

HTH
Dan

oesxyl
03-17-2008, 12:58 AM
binaryWeapon code:


var list1=new Array('wordA','wordB','wordC','wordD');
var list2=new Array('word1','word2','word3');

function combinations(array1, array2){
var combos="";
for(x=0; x<array1.length; x++){
for(y=0; y<array2.length; y++){
combos+=array1[x]+' '+array2[y]+', ';
}
}
return combos;
}



$list1=array('wordA','wordB','wordC','wordD');
$list2=array('word1','word2','word3');

function combinations($array1, $array2){
$combos="";
$array1len=count($array1);
$array2len=count($array2);
for($x=0; $x<$array1len; $x++){
for($y=0; $y<$array2len; $y++){
$combos.=$array1[$x].' '.$array2[$y].', ';
}
}
return $combos;
}

best regards

binaryWeapon
03-17-2008, 04:20 PM
The way I coded it, the function would show every possible combination, so the code

var list1=new Array('buy','purchase');
var list2=new Array('food','grub');
var combos="";

function combinations(array1, array2)
{
for(x=0; x<array1.length; x++)
{
for(y=0; y<array2.length; y++)
{
combos+=array1[x]+' '+array2[y]+', ';
}
}

for(a=0; a<array2.length; a++)
{
for(b=0; b<array1.length; b++)
{
combos+=array2[a]+' '+array1[b]+', ';
}
}
return combos;
}

alert(combinations(list1,list2));
Would alert "Buy food, buy grub, purchase food, purchase grub,..." and then continue with the words food and grub first, so the same two words would reappear, but in a different order... "food buy, food purchase, grub buy, grub purchase". If you just need one set of words at the beginnings of each string of words, use oesxyl's, which works perfectly.

Cheers!



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum