Pascal/Turbo Pascal - No entiendo por qué siempre retorna FALSE

 
Vista:

No entiendo por qué siempre retorna FALSE

Publicado por Agusin (2 intervenciones) el 07/11/2012 15:11:06
Hola, en la facultad tengo que entregar una tarea que consiste en resolver un sudoku. Estaba creando la funcion
function SudokuCorrecto(tablero: TipoTablero) : boolean;
{ retorna true si los valores asignados respetan las reglas de buena formación }

Aquí va el codigo adjunto, no entiendo por qué me devuelve siempre false si alguien puede ayudarme muchas gracias.

// type
Rango9 = 0..8;
Digito = '0'..'9';
TipoTablero = array [Rango9,Rango9] of Digito; //

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
function SudokuCorrecto(tablero: TipoTablero) : boolean;
var
i, j: integer;
exitof, exitoc : boolean;
begin
exitof := false;
exitoc := false;
i := 1;
j := 1;
while  (not exitof) and (i<=9) do
	begin
		while (not exitof) and (j<=8) do
		begin
		exitof := (tablero[i,j] = tablero[i,j+1]);
		j := j+1
		end;
		i := i+1
		end;
i := 1;
j := 1;
while (not exitoc) and (j<=9) do
begin
	while (not exitoc) and (i<=8) do
	begin
	exitoc := (tablero[i,j] = tablero[i,j+1]);
	i := i+1;
	end;
	j:=j+1;
	end;
 
SudokuCorrecto := not (exitoc or exitof);
 
end;
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder

No entiendo por qué siempre retorna FALSE

Publicado por ramon (2158 intervenciones) el 07/11/2012 21:37:43
Me puedes explicar porque avanzas en los dos el mismo ,

exitof := (tablero[i,j] = tablero[i,j+1]);

exitoc := (tablero[i,j] = tablero[i,j+1]);

no tendria que avanzar en estr [ i ].
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar

No entiendo por qué siempre retorna FALSE

Publicado por Agusin (2 intervenciones) el 07/11/2012 22:21:19
Ya arreglé esa parte del código, pero aun asi poniendo en la cuando le asigno el valor a SudokuCorrecto aunque ponga SudokuCorrecto := true, sigue largando false cuando uso el programa de prueba que me dio la facultad :( no entiendo...

Aquí van los 2 codigos el del programa de prueba y la función

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
program Sudoku(input,output);
type
   Rango9   = 0..8;
   Digito   = '0'..'9';
   TipoTablero = array [Rango9,Rango9] of Digito;
   ConjuntoDigito = set of Digito;
   TipoCandidatos = array [Rango9,Rango9] of ConjuntoDigito;
 
 
procedure LeerSudoku(var sudoku	: TipoTablero);
{ ingresa un tablero desde la entrada }
var
   i,j : Rango9;
begin
   for i:= 0 to 8 do
   begin
      for j:= 0 to 8 do
	 read(sudoku[i,j]);
      readln;
   end;
end; { LeerSudoku }
 
 
procedure MostrarConjunto(conj : ConjuntoDigito);
{ despliega un conjunto de digitos }
var
   c : digito;
begin
   write('{');
   for c:= '1' to '9' do
      if c in conj then
	 write(c)
      else
	 write('.');
   write('}');
end; { MostrarConjunto }
 
procedure MostrarTableroCandidatos(tablero : TipoTablero; candidatos: TipoCandidatos );
{ despliega el tablero
  las celdas ocupadas aparecen con su valor
  las celdas libres aparecen con su conjunto de candidatos
}
var
   i,j : rango9;
begin
   for i:= 0 to 8 do
   begin
      for j:= 0 to 8 do
      begin
	 if tablero[i,j] = '0' then
	    MostrarConjunto(candidatos[i,j])
	 else
	    write(tablero[i,j]:11);
	 write(' ');
      end;
      writeln;
   end;
end; { MostrarTableroCandidatos }
 
 
{$I t20.pas}
 
 
var
   tablero    : TipoTablero;
   candidatos : TipoCandidatos;
begin
   LeerSudoku(tablero);
   Writeln('Sudoku Correcto: ', SudokuCorrecto(tablero));
end.


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
function SudokuCorrecto(tablero: TipoTablero) : boolean;
var
i, j: integer;
exitof, exitoc : boolean;
begin
exitof := false;
exitoc := false;
i := 1;
j := 1;
while  (not exitof) and (i<=9) do
	begin
		while (not exitof) and (j<=8) do
		begin
		exitof := (tablero[i,j] = tablero[i,j+1]);
		j := j+1;
		end;
		i := i+1;
		end;
i := 1;
j := 1;
while (not exitoc) and (j<=9) do
begin
	while (not exitoc) and (i<=8) do
	begin
	exitoc := (tablero[i,j] = tablero[i+1,j]);
	i := i+1;
	end;
	j:=j+1;
	end;
 
SudokuCorrecto := not (exitoc or exitof);
 
end;
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar