Hello guys,
I have script
PHP Code:
<?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 = "ABCDEFGHI"; $len = 4; $Return = Permutate($StartString, $len, $cnt); $i = $len -1; $cnt = sizeof($Return[$i]); $File = "AAAA.txt"; $f = fopen($File, 'w');
print "Returned <b>$cnt</b> permutations.<br><hr>"; //for ($i = 0; $i < $len; $i++) //{ for ($j = 0; $j < sizeof($Return[$i]); $j++) { fwrite ($f, $Return[$i][$j] . "/n"); } print "<br>";
//} ?>
How to change it for unique combinations like
ABCD ABDC ACBD ACDB ADBC ADCB
BACD BADC BCAD BCDA BDAC BDCA
CABD CADB CBAD CBDA CDAB CDBA
DABC DACB DBAC DBCA DCAB DCBA ?
|