Welcome Guest, Not a member yet? Register   Sign In
Three letter complete list
#1

[eluser]Total Shop UK[/eluser]
I am trying to create a list that will contain every word using up to three letters.

a,b,c...z
aa,ab,ac...zz
aaa,aab,aac...zzz

Edit: worked it out but the other guys code looks cleaner
Code:
$letters=array('a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z');
$arr1=$letters;
$arr2=$letters;
$arr3=$letters;
foreach ($arr1 as $value1) {
    echo $value1."\r\n";
    foreach ($arr2 as $value2) {
        echo $value1.$value2."\r\n";
        foreach ($arr3 as $value3){
            echo $value1.$value2.$value3."\r\n";
        }
    }
}
#2

[eluser]mddd[/eluser]
You could make it even nicer by doing a recursive function to allow any length you want.
But I think this will work. 1 to 3 letters in length.
Code:
$results = array();

for($c1=1;$c1<27;$c1++) { // count c1 from 1 (=a) to 26 (=z)
for($c2=0;$c2<27;$c2++) { // count c2 from 0 (=nothing) to 26 (=z)
for($c3=0;$c3<27;$c3++) { // count c3 from 0 =nothing) to 26 (=z)

  $word = chr($c1+96);
  if ($c2) $word .= chr($c2+96);
  if ($c3) $word .= chr($c2+96);
  $results[] = $word;

}
}
}
// after this, $results will contain all the variations.
#3

[eluser]Total Shop UK[/eluser]
Looks very promising, but results using your code show

Code:
ja jaa jaa jaa jaa jaa jaa jaa jaa jaa jaa jaa jaa jaa jaa jaa jaa jaa jaa jaa jaa jaa jaa jaa jaa jaa jaa

instead of

Code:
ja jaa jab jac jad jae jaf jag jah jai jaj jak jal jam jan jao jap jaq jar jas jat jau jav jaw jax jay jaz
#4

[eluser]mddd[/eluser]
My mistake.
See the line : if ($c3) ....
I wrote chr($2+96) in stead of chr($c3+96).. so it uses the second letter twice to build the word.
#5

[eluser]Total Shop UK[/eluser]
Many thanks Smile




Theme © iAndrew 2016 - Forum software by © MyBB