I\'m attempting to write a program that will generate a text file with every possible permutation of the alphabet from one character up to twenty-nine characters. I\'ve chosen 2
function p($length, $partial)
{
if ($length == 0) return $partial;
$ans = array();
foreach (range('a', 'z') as $i)
{
$ans[] = p($length -1, $partial . $i);
}
return $ans;
}
$top = 3;
//$f = fopen('out.txt');
for ($l = 1; $l < $top+1; $l++)
{
print_r(p($l), '');
//fwrite($p($l), '');
}
If you want to set $top
to 29 and give it a try go ahead. I'm not going to.
EDIT - print_r(p($l), '');
---> print_r(p($l, ''));
PHP keeps impressing me with its tolerance for mistakes. Missing a 'required' argument to my p
? no problem itll just be empty string somehow (or zero, or false, situation depending). Second '' argument to print_r? no difference, gets treated like the default false
anyway
EDIT
I don't know what the hell I was doing here. The different return types of p are quite odd, and will return a compound array with a weird structure.
This is a far better solution anyway
$lengthDesired = 29;
for($i='a'; $i != str_pad('',$lengthDesired+1,'a'); $i++)
echo $i .', ';