Board index   FAQ   Search  
Register  Login
Board index PHP PHP Scripts

Combinatoric

Links for php scripts

Moderators: macek, egami, gesf

Combinatoric

Postby turbo535 » Tue Aug 09, 2011 6:33 am

Hello guys,

I have script:

<?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 = "ABCD";
$len = 4;
$Return = Permutate($StartString, $len, $cnt);

$i = $len -1;

$cnt = sizeof($Return[$i]);

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>";
//}
?>

How to change it for unique combinations only. Now with this scipt I can get AAAA, AAAB, AAAC, but I need only AABB, AABA, AACC, no more 2 the same characters in line. Thank you.
turbo535
New php-forum User
New php-forum User
 
Posts: 1
Joined: Tue Aug 09, 2011 6:22 am

Return to PHP Scripts

Who is online

Users browsing this forum: No registered users and 1 guest

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.

cron