krot

перебор всех комбинаций

Sep 11th, 2020 (edited)
525
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.36 KB | None | 0 0
  1. <?
  2. $n=8;//длина
  3. $m=2;
  4. $a=new SplFixedArray($n);
  5. $out=array();
  6.  
  7. rec(0);
  8. print_r($out);
  9.  
  10. function out(){
  11.     global $a,$n,$out;
  12.     $tmp='';
  13.     for($i=0;$i<$n;++$i){
  14.         $tmp.=$a[$i];
  15.     }
  16.     $out[]=$tmp;
  17. }
  18. function rec($inx){
  19.     global $a,$m,$n;
  20.     if($inx==$n){
  21.         out();
  22.         return;
  23.     }
  24.     for($i=1;$i<=$m;++$i){
  25.         $a[$inx]=$i;
  26.         rec($inx+1);
  27.     }
  28. }
Add Comment
Please, Sign In to add comment