Forward, the science is a sun ...
Dropdown Menu
Dropdown Menu
Предишна Страница/Назад
Следваща Страница/Напред
Основен Списък
Търсене
 

→ Магическия квадрат на Албрехт Дюрер ←
- Многообразието -

<< Към основната страница

Ето един възможен PHP код, с който могат да се намерят всичките възможни квадрати на Дюрер и с който е генерирана страницата показваща всичките 384 такива квадрати:


<?php
$counter
=0;
$rows=0;
    echo 
'<table class="style4">'// main table

for ($a=1$a<=16;$a++):
// for ($a=16; $a>=1;$a--):
    
for ($b=1$b<=16;$b++):
//    for ($b=3; $b<=3;$b++):
        
for ($c=1$c<=16;$c++):
//        for ($c=5; $c<=5;$c++):
            
for ($d=1$d<=16;$d++):
//            for ($d=13; $d<=13;$d++):
if ($a!==$b && $a!==$c && $a!==$d &&
               
$b!==$c && $b!==$d &&
                             
$c!==$d &&
    
1<= 34-$a-$b-$d    && 34-$a-$b-$d <=16    && // 13
    
1<= 34-$a-$b-$c    && 34-$a-$b-$c <=16    && // 21
    
1<= $b-$c+$d    && $b-$c+$d <=16    && // 22
    
1<= $a+$c-$d    && $a+$c-$d <=16     //24
    // the other combinatiuons are between 1 and 16 as a consequence of the above restrictions
    
): // conditions on the independent parameters

    
$square=array(
                array(
$a            ,$b                ,34-$a-$b-$d    ,$d            ),
                array(
$c            ,34-$a-$b-$c    ,$b-$c+$d        ,$a+$c-$d    ),
                array(
17-$a-$c+$d    ,17-$b+$c-$d    ,-17+$a+$b+$c    ,17-$c        ),
                array(
17-$d        ,-17+$a+$b+$d        17-$b         ,17-$a        )
    );
    
$varification='Yes';
    
    for (
$i=0$i<=3$i++):
    for (
$j=0$j<=3$j++):
    for (
$k=0$k<=3$k++):
    for (
$l=0$l<=3$l++):
        if( !(
$i==$k && $j==$l) && $square[$i][$j] == $square[$k][$l] ){ // all elements must be different
                
$varification='No';
            };
    endfor; 
//$l
    
endfor; //$k
    
endfor; //$j
    
endfor; //$i

### print squares
    
if($varification!=='No'){ // all conditions are fulfilled!
        
$counter+=1;
        if(
$counter%4==1){ // begin a row of the main table
        
$rows+=1;
            echo 
'<tr style="background-color:';
            if(
$rows%2==0){echo'#EFF2EA';}
            if(
$rows%2==1){echo'#ECD899';}
            echo
';">';
            };
        
        if(
$counter==370){echo'<td style="background-color:yellow">';} // the Dures square is in yellow
        
else{echo '<td>';};
        echo 
"<span style=\"color:green; font-size: 12px;\"><span style=\"color:black;font-size: 15px;\">No.$counter</span> (a=$a, b=$b, c=$c, d=$d)</span>";
        
        echo 
'<table class="style4">'// the table with the square - BEGINNING
        
for ($i=0$i<=3$i++):
            echo 
'<tr>';
        for (
$j=0$j<=3$j++):
            echo 
'<td>'.$square[$i][$j].'</td>';
        
        endfor; 
//$j
            
echo '</tr>';
        endfor; 
//$i
        
echo'</table>'// the table with the square - END
        
        
echo '</td>';
        if(
$counter%4==0){echo '</tr>';}; // end a row of the main table
    
}; // all conditions are fulfilled!

endif; // conditions on the independent parameters
endfor; //$d
endfor; //$c
endfor; //$b
endfor; //$a

    
echo'</table>'// main table

?>

<< Към основната страница

 
® “СБОРИЩЕТО на физиците 1981”  © ➜ Автор/От: Божидар Илиев (Божо) 2006—2024