Desafio : Laberinto Martes 14 Marzo 2007
Consiste de un Laberinto en una Matriz 24x24 , donde la Pared es representada por un 1 , Espacio Libre por un 0 y el Queso por un 2
El Laberinto es representado por una Matriz 24x24, inicialmente se encuentra sin el queso (solo paredes 1 y espacios libres 0)
Luego aplicamos la funcion queso la cual aleatoriamente inserta en un espacio libre el Queso (2) en el laberinto
¿ Que debemos Realizar ?
Un Algoritmo,Script, Funcion, Clase, etc ... que simule un Raton, es decir comienze en un Punto Inicial (puede ser aleatorio este punto) y luego valla avanzando hasta encontrar el queso, debe entregar el camino recorrido hasta el queso , la posicion del queso y numeros de casillas visitas. Pueden utilizar cualquier tecnica de Programacion (Dividir y Venceras, Recursivas, Iterativas, Vuelta Atras, etc ..)
Las soluciones la pueden postear apartir del dia Domingo 25 Marzo 2007 (Para que todos tengan la Oportunidad de Participar)
*** Se Adjunta ***
- Matriz del Laberinto (Con Paredes y Espacios Vacios)
Código PHP:
<?
$array = array (
0 => array(
0 => 1,
1 => 1,
2 => 1,
3 => 1,
4 => 1,
5 => 1,
6 => 1,
7 => 1,
8 => 1,
9 => 1,
10 => 1,
11 => 1,
12 => 1,
13 => 1,
14 => 1,
15 => 1,
16 => 1,
17 => 1,
18 => 1,
19 => 1,
20 => 1,
21 => 1,
22 => 1,
23 => 1,
),
1 => array(
0 => 1,
1 => 0,
2 => 1,
3 => 0,
4 => 0,
5 => 0,
6 => 0,
7 => 0,
8 => 0,
9 => 1,
10 => 0,
11 => 0,
12 => 0,
13 => 0,
14 => 0,
15 => 1,
16 => 0,
17 => 0,
18 => 0,
19 => 0,
20 => 0,
21 => 0,
22 => 0,
23 => 1,
),
2 => array(
0 => 1,
1 => 0,
2 => 1,
3 => 0,
4 => 1,
5 => 1,
6 => 1,
7 => 1,
8 => 0,
9 => 1,
10 => 1,
11 => 1,
12 => 1,
13 => 1,
14 => 0,
15 => 1,
16 => 0,
17 => 0,
18 => 1,
19 => 0,
20 => 1,
21 => 0,
22 => 0,
23 => 1,
),
3 => array(
0 => 1,
1 => 0,
2 => 1,
3 => 0,
4 => 0,
5 => 0,
6 => 0,
7 => 1,
8 => 0,
9 => 1,
10 => 0,
11 => 0,
12 => 0,
13 => 0,
14 => 0,
15 => 1,
16 => 1,
17 => 0,
18 => 1,
19 => 1,
20 => 1,
21 => 0,
22 => 1,
23 => 1,
),
4 => array(
0 => 1,
1 => 0,
2 => 1,
3 => 1,
4 => 1,
5 => 1,
6 => 0,
7 => 1,
8 => 0,
9 => 1,
10 => 0,
11 => 1,
12 => 0,
13 => 1,
14 => 0,
15 => 1,
16 => 0,
17 => 0,
18 => 0,
19 => 0,
20 => 0,
21 => 0,
22 => 0,
23 => 1,
),
5 => array(
0 => 1,
1 => 0,
2 => 0,
3 => 0,
4 => 0,
5 => 0,
6 => 0,
7 => 1,
8 => 0,
9 => 1,
10 => 1,
11 => 1,
12 => 0,
13 => 1,
14 => 0,
15 => 1,
16 => 1,
17 => 0,
18 => 1,
19 => 0,
20 => 1,
21 => 0,
22 => 0,
23 => 1,
),
6 => array(
0 => 1,
1 => 1,
2 => 1,
3 => 0,
4 => 1,
5 => 0,
6 => 0,
7 => 1,
8 => 0,
9 => 0,
10 => 0,
11 => 0,
12 => 0,
13 => 1,
14 => 1,
15 => 1,
16 => 1,
17 => 1,
18 => 1,
19 => 0,
20 => 1,
21 => 1,
22 => 1,
23 => 1,
),
7 => array(
0 => 1,
1 => 0,
2 => 0,
3 => 0,
4 => 1,
5 => 0,
6 => 0,
7 => 1,
8 => 1,
9 => 1,
10 => 1,
11 => 1,
12 => 0,
13 => 0,
14 => 0,
15 => 0,
16 => 0,
17 => 0,
18 => 0,
19 => 0,
20 => 0,
21 => 0,
22 => 0,
23 => 1,
),
8 => array(
0 => 1,
1 => 1,
2 => 1,
3 => 0,
4 => 1,
5 => 0,
6 => 0,
7 => 0,
8 => 0,
9 => 0,
10 => 0,
11 => 1,
12 => 0,
13 => 1,
14 => 1,
15 => 1,
16 => 0,
17 => 1,
18 => 1,
19 => 0,
20 => 1,
21 => 1,
22 => 0,
23 => 1,
),
9 => array(
0 => 1,
1 => 0,
2 => 1,
3 => 0,
4 => 1,
5 => 0,
6 => 1,
7 => 1,
8 => 1,
9 => 1,
10 => 1,
11 => 1,
12 => 0,
13 => 1,
14 => 0,
15 => 1,
16 => 0,
17 => 0,
18 => 1,
19 => 0,
20 => 1,
21 => 0,
22 => 0,
23 => 1,
),
10 => array(
0 => 1,
1 => 0,
2 => 1,
3 => 0,
4 => 1,
5 => 0,
6 => 0,
7 => 0,
8 => 0,
9 => 0,
10 => 0,
11 => 0,
12 => 0,
13 => 1,
14 => 0,
15 => 1,
16 => 0,
17 => 1,
18 => 1,
19 => 0,
20 => 1,
21 => 0,
22 => 1,
23 => 1,
),
11 => array(
0 => 1,
1 => 0,
2 => 1,
3 => 0,
4 => 1,
5 => 0,
6 => 1,
7 => 1,
8 => 1,
9 => 1,
10 => 1,
11 => 0,
12 => 1,
13 => 1,
14 => 0,
15 => 0,
16 => 0,
17 => 1,
18 => 0,
19 => 0,
20 => 1,
21 => 0,
22 => 0,
23 => 1,
),
12 => array(
0 => 1,
1 => 0,
2 => 0,
3 => 0,
4 => 1,
5 => 0,
6 => 0,
7 => 0,
8 => 0,
9 => 0,
10 => 1,
11 => 0,
12 => 0,
13 => 1,
14 => 0,
15 => 1,
16 => 1,
17 => 1,
18 => 1,
19 => 1,
20 => 1,
21 => 0,
22 => 1,
23 => 1,
),
13 => array(
0 => 1,
1 => 0,
2 => 1,
3 => 0,
4 => 0,
5 => 0,
6 => 0,
7 => 1,
8 => 1,
9 => 1,
10 => 1,
11 => 1,
12 => 0,
13 => 1,
14 => 0,
15 => 1,
16 => 0,
17 => 0,
18 => 0,
19 => 0,
20 => 0,
21 => 0,
22 => 0,
23 => 1,
),
14 => array(
0 => 1,
1 => 0,
2 => 1,
3 => 1,
4 => 1,
5 => 0,
6 => 0,
7 => 1,
8 => 0,
9 => 0,
10 => 1,
11 => 0,
12 => 0,
13 => 1,
14 => 0,
15 => 1,
16 => 1,
17 => 1,
18 => 1,
19 => 0,
20 => 1,
21 => 1,
22 => 0,
23 => 1,
),
15 => array(
0 => 1,
1 => 0,
2 => 0,
3 => 0,
4 => 1,
5 => 0,
6 => 0,
7 => 1,
8 => 0,
9 => 0,
10 => 0,
11 => 0,
12 => 1,
13 => 1,
14 => 0,
15 => 0,
16 => 0,
17 => 0,
18 => 0,
19 => 0,
20 => 0,
21 => 0,
22 => 0,
23 => 1,
),
16 => array(
0 => 1,
1 => 1,
2 => 1,
3 => 0,
4 => 1,
5 => 1,
6 => 1,
7 => 1,
8 => 0,
9 => 1,
10 => 0,
11 => 0,
12 => 1,
13 => 0,
14 => 0,
15 => 1,
16 => 1,
17 => 0,
18 => 0,
19 => 1,
20 => 0,
21 => 1,
22 => 1,
23 => 1,
),
17 => array(
0 => 1,
1 => 0,
2 => 1,
3 => 0,
4 => 1,
5 => 0,
6 => 0,
7 => 0,
8 => 0,
9 => 1,
10 => 1,
11 => 0,
12 => 1,
13 => 0,
14 => 1,
15 => 0,
16 => 1,
17 => 0,
18 => 1,
19 => 1,
20 => 0,
21 => 1,
22 => 0,
23 => 1,
),
18 => array(
0 => 1,
1 => 0,
2 => 1,
3 => 0,
4 => 1,
5 => 0,
6 => 1,
7 => 1,
8 => 0,
9 => 0,
10 => 1,
11 => 0,
12 => 0,
13 => 0,
14 => 1,
15 => 0,
16 => 1,
17 => 0,
18 => 0,
19 => 1,
20 => 0,
21 => 1,
22 => 0,
23 => 1,
),
19 => array(
0 => 1,
1 => 0,
2 => 0,
3 => 0,
4 => 1,
5 => 0,
6 => 0,
7 => 1,
8 => 0,
9 => 0,
10 => 1,
11 => 0,
12 => 1,
13 => 0,
14 => 1,
15 => 0,
16 => 0,
17 => 0,
18 => 1,
19 => 1,
20 => 0,
21 => 0,
22 => 0,
23 => 1,
),
20 => array(
0 => 1,
1 => 0,
2 => 1,
3 => 0,
4 => 1,
5 => 1,
6 => 0,
7 => 1,
8 => 0,
9 => 1,
10 => 1,
11 => 0,
12 => 1,
13 => 0,
14 => 1,
15 => 1,
16 => 1,
17 => 0,
18 => 0,
19 => 1,
20 => 1,
21 => 1,
22 => 0,
23 => 1,
),
21 => array(
0 => 1,
1 => 0,
2 => 1,
3 => 0,
4 => 0,
5 => 0,
6 => 0,
7 => 1,
8 => 0,
9 => 1,
10 => 0,
11 => 0,
12 => 1,
13 => 0,
14 => 0,
15 => 0,
16 => 1,
17 => 0,
18 => 1,
19 => 1,
20 => 1,
21 => 1,
22 => 0,
23 => 1,
),
22 => array(
0 => 1,
1 => 0,
2 => 1,
3 => 0,
4 => 1,
5 => 1,
6 => 1,
7 => 1,
8 => 0,
9 => 0,
10 => 0,
11 => 1,
12 => 1,
13 => 1,
14 => 0,
15 => 0,
16 => 1,
17 => 0,
18 => 0,
19 => 0,
20 => 0,
21 => 0,
22 => 0,
23 => 1,
),
23 => array(
0 => 1,
1 => 1,
2 => 1,
3 => 1,
4 => 1,
5 => 1,
6 => 1,
7 => 1,
8 => 1,
9 => 1,
10 => 1,
11 => 1,
12 => 1,
13 => 1,
14 => 1,
15 => 1,
16 => 1,
17 => 1,
18 => 1,
19 => 1,
20 => 1,
21 => 1,
22 => 1,
23 => 1,
),
) ;
?>
Código PHP:
<?
function queso(&$array,$p = NULL)
{
// Ingresar Queso al Laberinto
$d=count($array);
$t[0]=rand(0,($d-1));
$t[1]=rand(0,($d-1));
if ( $array[$t[0]][$t[1]] == 0 )
{
// Posicion Vacia
// Guardamos Queso
$array[$t[0]][$t[1]] = 2;
return TRUE;
}
else
{
return ( queso($array) );
}
}
?>
==============================
Soluciones Recibidas hasta el Momento
Solucion de nicolaspar
Solucion de IngProd
Solucion de Panino5001
Solucion de DeeR
Solucion de Falhor
Solucion de IngProdr
Solucion de okram