Beruflich Dokumente
Kultur Dokumente
<?php
define('N', 9);
define('WAIT_TIME', 3);
define('TRACE', true);
$GLOBALS['TOTAL_SOLUTIONS'] = 0;
$GLOBALS['SOLUTIONS'] = array();
$square = array();
for ($i = 0; $i < N; ++$i) {
for ($j = 0; $j < N; ++$j) {
$square[$i][$j] = 0;
}
}
echo 'NxN latin square with N='.N.'. Let\'s start filling with colors..'.PHP_EOL;
latinSquare($square, 1);
echo 'Total solutions found: '.$GLOBALS['TOTAL_SOLUTIONS'].PHP_EOL;
//Funcion principal
//Funciones auxiliares
function writeToScreen($square)
{
for ($i = 0; $i < N; ++$i) {
for ($j = 0; $j < N; ++$j) {
echo str_pad($square[$i][$j], 3, ' ', STR_PAD_BOTH);
}
echo PHP_EOL;
}
}
return false;
}
// rows
$cont = array_fill(1, N, 0);
for ($j = 0; $j < N; ++$j) {
if ($square[$i][$j] != 0) {
++$cont[$square[$i][$j]];
}
}
foreach ($cont as $value) {
if ($value > 1) {
return false;
}
}
}
return true;
}
// Fill squares with colors and return array with all possible fillings.
function completions($square, $color)
{
$completions = array();
$square[0][$j] = 0;
}
}
return $completions;
}
function completionsRecursive(&$completions, $square, $color, $row)
{
for ($j = 0; $j < N; ++$j) {
if ($square[$row][$j] == 0) {
$square[$row][$j] = $color;
if (possible($square)) {
if ($row + 1 < N) {
completionsRecursive($completions, $square, $color, $row + 1);
} else {
$completions[] = $square;
}
}
$square[$row][$j] = 0;
}
}
}
______________________
otro
_______________________
class Cuadrado{
valor=v;
return valor;
}
for (i=0;i<=valor;i++){
array[i]=i;
}
//recorrer los numeros
public void recorrerValores(){
//aqui se recorre
int [] array2 = new int [valor] ;
for (i=0 ; i < array.length ; i++){
if (i==array.length-1){
array2[1]=array[i];
}else{
array2[i] = array[i+1];
}
}
array2[i] = array[i];