2
2
2
2
2
2
2
2
2
2
3
3
3
3
3
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
4
4
4
4
4
4
4
4
4
4
4
4
4
4
4
code:
<?php
    function divHtml($dtype, $x, $y) //$dtype: (1)=1x1yellow, (2)=1x2, (3)=2x1, (4)=1x1white
    {  $ww =($dtype ==3) ?'200px':'100px';    $hh =($dtype==2)?'200px':'100px'; $bgcols =array('#ff0', '#f00', '#00f', '#fff');
       $xx =($x*100) .'px';                   $yy =($y*100) .'px';              $bgc    =$bgcols[$dtype-1];
       return "<div style='position:absolute; width:$ww;height:$hh; left:$xx;top:$yy; background:$bgc;'> $dtype </div>";
    }
    $divs =array(); //real divs array (html inside)
    $cells =array(); //logical filled/notFilled (0/1) array
    for ($i=0; $i<60; $i++) $cells[$i] =0;  

    function reserve($dtype, $x, $y)
    {  global $cells, $divs;      if ($y*10+$x >59 ||($cells[$y*10+$x])) return false;
       switch ($dtype)
       {  case 2: if ($y ==5 || $cells[$y*10+$x] ||$cells[($y+1)*10+$x]) return false;  $cells[($y+1)*10+$x] =1; break;
          case 3: if ($x ==9 || $cells[$y*10+$x] ||$cells[$y*10+$x+1])   return false;  $cells[$y*10+$x+1] =1;   break;
       }
       $cells[$y*10+$x] =1;      $divs[] =divHtml($dtype, $x, $y);       return true;
    }

    for($i = 0; $i < 10; $i ++) while (!reserve(2, rand(0,9), rand(0,5))) ; //adding 10 blocks of type2 (20cellsTotal)
    for($i = 0; $i <  5; $i ++) while (!reserve(3, rand(0,9), rand(0,5))) ; //adding  5 blocks of type3 (10cellsTotal)
    for($i = 0; $i < 15; $i ++) while (!reserve(1, rand(0,9), rand(0,5))) ; //adding 15 blocks of type1 (15cellsTotal)
    for($i = 0; $i < 60; $i ++) if (!$cells[$i]) reserve(4, $i%10, floor($i/10)) ; //filling rest 15 cells with type4
                   //^go through all cells, but filling only 15

    echo '<div style="position:absolute; width:1000px; height:600px;">';
       foreach ($divs as $single) echo $single;
    echo '</div>';
    
    echo "<div style='position:absolute;top:620px;left:10px; '>code:<br><pre>"
         .htmlentities(file_get_contents('testDivs10x6.php')) ."</pre></div>";
?>