php - Only generate string with a Max of X length and Min of X -
i have script generates possible permutations of something. thing is, don't know how make list max of, lets say, 10 characters , minimum of 3 characters.
<?php ini_set('memory_limit', '-1'); ini_set('max_execution_time', '0'); $possible = "abcdefghi"; $input = "$possible"; function string_getpermutations($prefix, $characters, &$permutations) { if (count($characters) == 1) $permutations[] = $prefix . array_pop($characters); else { ($i = 0; $i < count($characters); $i++) { $tmp = $characters; unset($tmp[$i]); string_getpermutations($prefix . $characters[$i], array_values($tmp), $permutations); } } } $characters = array(); ($i = 0; $i < strlen($input); $i++) $characters[] = $input[$i]; $permutations = array(); print_r($characters); string_getpermutations("", $characters, $permutations); print_r($permutations); ?>
currently outputs 400,000 possibilities , that's tiny fraction of want. (i literally want possibilities, huge problem memory usage, that's problem.)
does know how this?
Comments
Post a Comment