combinatoric
Posted: Tue Aug 09, 2011 7:21 am
Hello guys, I have script:
How to change this script that would return only unique combinations and only combinations of 4 charters, not 1, 2 or 3? I mean I need only AAAA combinations not AAA, AA. Thank you.
Code: Select all
<?php
function Permutate($strDataIn, $Length, &$PermutateCount) {
for ($i = 0; $i < strlen($strDataIn); $i++) {
$PermArray[0][$i] = substr($strDataIn, $i, 1);
$temp[$i] = substr($strDataIn, $i, 1);
$temp2[0][$i] = substr($strDataIn, $i, 1);
}
for ($i = 1; $i < $Length; $i++) {
for ($k = 0; $k < strLen($strDataIn); $k++) {
for ($j = 0; $j < sizeof($temp2[$i - 1]); $j++) {
$PermArray[$i][($k * sizeof($temp2[$i - 1])) + $j] = $temp[$k] . $temp2[$i - 1][$j];
$temp2[$i][($k * sizeof($temp2[$i - 1])) + $j] = $temp[$k] . $temp2[$i - 1][$j];
}
}
}
$k = 0;
for ($i = 0; $i < $Length; $i++) {
$k += sizeof($PermArray[$i]);
}
$PermutateCount = $k;
return $PermArray;
}
$StartString = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
$len = 4;
$Return = Permutate($StartString, $len, $cnt);
print "Returned <b>$cnt</b> permutations.<br><hr>";
for ($i = 0; $i < $len; $i++) {
for ($j = 0; $j < sizeof($Return[$i]); $j++) {
print $Return[$i][$j] . "<br>";
}
print "<br>";
}
?>