<?php
$counter=0;
$rows=0;
$SQUARES=array();
echo '<table class="style4">'; // main table
// for ($a=1; $a<=16;$a++):
for ($a=16; $a>=1;$a--): // Correction to get the Durers square
// for ($b=1; $b<=16;$b++):
for ($b=3; $b<=18;$b++): // Correction to get the Durers square
for ($c=1; $c<=16;$c++):
for ($d=1; $d<=16;$d++):
if($b>16){$b=$b-16;}; // Correction to get the Durers square
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 )
);
/* echo "<pre>". $square[0][0].' '.$square[0][1].' '.$square[0][2].' '.$square[0][3].' ' ."</pre>";
echo "<pre>". $square[1][0].' '.$square[1][1].' '.$square[1][2].' '.$square[1][3].' ' ."</pre>";
echo "<pre>". $square[2][0].' '.$square[2][1].' '.$square[2][2].' '.$square[2][3].' ' ."</pre>";
echo "<pre>". $square[3][0].' '.$square[3][1].' '.$square[3][2].' '.$square[3][3].' ' ."</pre><br>";
*/
$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] ){
$varification='No';
}//else{echo "i=$i, j=$j, k=$k, l=$l<br>";};
//echo "i=$i, j=$j, k=$k, l=$l<br>";
// echo "varification=$varification<br> i=$i, j=$j, k=$k, l=$l<br>";
endfor; //$l
endfor; //$k
endfor; //$j
endfor; //$i
if($varification!=='No'){ // all conditions are fulfilled!
$counter+=1;
$SQUARES[$counter]=$square;// number => square
};
endif; // all conditions are fulfilled!
endfor; //$d
endfor; //$c
if($b<3){$b=$b+16;}; // Correction to get the Durers square
endfor; //$b
endfor; //$a
foreach($SQUARES as $key_1 => $TEMP_1) :
foreach($SQUARES as $key_2 => $TEMP_2) :
$Symmetric=0;
for ($i=0; $i<=3; $i++):
for ($j=0; $j<=3; $j++):
if ($key_1 < $key_2 &&
$TEMP_1[$i][$j] == $TEMP_2[3-$i][$j] // HORIZONTAL
):
$Symmetric+=1;
endif;
if($Symmetric==16) {unset($SQUARES[$key_2]); };
endfor;
endfor;
for ($i=0; $i<=3; $i++):
for ($j=0; $j<=3; $j++):
if ($key_1 < $key_2 &&
$TEMP_1[$i][$j] == $TEMP_2[$i][3-$j] // VERTICAL
):
$Symmetric+=1;
endif;
if($Symmetric==16) {unset($SQUARES[$key_2]); };
endfor;
endfor;
for ($i=0; $i<=3; $i++):
for ($j=0; $j<=3; $j++):
if ($key_1 < $key_2 &&
$TEMP_1[$i][$j] == $TEMP_2[3-$i][3-$j] // ROTATION 90
):
$Symmetric+=1;
endif;
if($Symmetric==16) {unset($SQUARES[$key_2]); };
endfor;
endfor;
for ($i=0; $i<=3; $i++):
for ($j=0; $j<=3; $j++):
if ($key_1 < $key_2 &&
$TEMP_1[$i][$j] == $TEMP_2[3-$j][3-$i] // ROTATION 180
):
$Symmetric+=1;
endif;
if($Symmetric==16) {unset($SQUARES[$key_2]); };
endfor;
endfor;
for ($i=0; $i<=3; $i++):
for ($j=0; $j<=3; $j++):
if ($key_1 < $key_2 &&
$TEMP_1[$i][$j] == $TEMP_2[3-$j][$i] // ROTATION 270
):
$Symmetric+=1;
endif;
if($Symmetric==16) {unset($SQUARES[$key_2]); };
endfor;
endfor;
for ($i=0; $i<=3; $i++):
for ($j=0; $j<=3; $j++):
if ($key_1 < $key_2 &&
$TEMP_1[$i][$j] == $TEMP_2[$j][$i] //TRANSPOSITION
):
$Symmetric+=1;
endif;
if($Symmetric==16) {unset($SQUARES[$key_2]); };
endfor;
endfor;
endforeach;
endforeach;
### print squares
$Number=0;
foreach($SQUARES as $TEMP) : // for any admitable square
$Number+=1;
if($Number%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">';}
// else{echo '<td>';};
if($Number==4){echo'<td style="background-color:yellow">';} // the Dures square is in yellow
else{echo '<td>';};
echo "<span style=\"color:green; font-size: 15px;\"><span style=\"color:black;font-size: 17px;\">No.$Number</span> </span>";
echo '<table class="style4">'; // the table with the square
for ($i=0; $i<=3; $i++):
echo '<tr>';
for ($j=0; $j<=3; $j++):
echo '<td>'.$TEMP[$i][$j].'</td>';
endfor; //$j
echo '</tr>';
endfor; //$i
echo'</table>';
echo '</td>';
if($rows%4==0){echo '</tr>';}; // end a row of the main table
endforeach; // for any admitable square
echo'</table>'; // main table
?>
|