PHP –– permutations
written by: admin
Date Written: 4/27/12
Last Updated: 5/28/12
<?php
$a=122;
$b=array();
while ($a<543){$a++;
$a1=substr($a,0,1);
$a2=substr($a,1,1);
$a3=substr($a,2,1);
if ($a3==6){$a2++;$a3=1;}
if ($a2==6){$a1++;$a2=1;}
$a="$a1"."$a2"."$a3";
if ($a>543)break;
if ($a1!=$a2 and $a1!=$a3 and $a2!=$a3)$b[]=$a;
}
echo"<pre>";
print_r($b);
echo"</pre>";
?>
demo
All this does is calculate all of the possible combinations of 3 non repeating digits of digits 1 – 5. You never know when this could be useful. You need to know all of the possible combinations in a lock or possible orders in a game.
TAGS: php