Ver Mensaje Individual
  #13  
Antiguo 19-11-2017
jhonalone jhonalone is offline
Miembro
 
Registrado: sep 2007
Ubicación: Madrid
Posts: 545
Reputación: 17
jhonalone Va por buen camino
¡¡FABULOSO!! maeyanes.

Tu trabajo ha sido MAGNÍFICO.

Funciona, perfectamente.

Sólo una pregunta. ¿Porqué todos los sudokus resueltos terminan con -1?

No es que sea un problema. La solución es correcta. Simplemente es una curiosidad.

He estado revisando
Código Delphi [-]
procedure TSudokuSolver.Solve(const ASudoku: string);
var
  S: TList;
  Q: TList>;
  I: Integer;

begin
  S := TList.Create;
  Q := TList>.Create;
  FAct := TList>.Create;
  FAq := TList>.Create;
  FSudoku := '';
  FCt := 0;
  for I := 0 to 161 do
    if I < 81 then
      S.Add(511)
    else
      S.Add(0);
  for I := 1 to Length(ASudoku) do
    if CharInSet(ASudoku[i], ['1'..'9']) then
      SetValue(I - 1, ASudoku[i], S);
  if Solver(S) then
  begin
    Q.Add(TList.Create);
    Q[0].AddRange(S)
  end;
  Cons(Q[0]);
  while (FCt < 81) and (FCt > -1) do
  begin
    if FCt2 < 0 then
    begin
      for I := 81 to 162 do
        FSudoku := FSudoku + IntToStr(Q[FCt][i]);
      Break
    end;
    SetValue(FCt2, ListPop(FAct[FCt]), Q[FCt]);
    if not Solver(Q[FCt]) then
    begin
      Q[FCt].Clear;
      Q[FCt].AddRange(FAq[FCt]);
      while (FAct[FCt].Count = 0) and (FCt > -1) do
      begin
        Dec(FCt);
        FCt2 := Q[FCt][162];
        Q[FCt].Clear;
        Q[FCt].AddRange(FAq[FCt])
      end;
    end
    else
    begin
      Inc(FCt);
      if Q.Count = FCt then
        Q.Add(TList.Create)
      else
        Q[FCt].Clear;
      Q[FCt].AddRange(Q[FCt - 1]);
      Cons(Q[FCt])
    end;
  end;
  S.Free;
  Q.Free
end;

Pero no encuentro el motivo.

No te entretengas en buscar la causa si no lo ves a simple vista. (Ya te dije que era una curiosidad y ya has hecho bastante esfuerzo.)

En Google Play tienes el sudoku al que voy a aplicar tu trabajo, (aunque antes tendré que adaptarlo para Android). La App es gratuita y se llama SudokuPlus. Busca por SudokuPlus Jhonalone, si quieres verla. A falta de una solución mejor (como es ésta) estaba utilizando un generador aleatorio, que voy a sustituir por éste que, según su autor siempre genera una solución única. El generador aleatorio, a veces, no lo hace.

Nunca olvidaré tu excelente contribución.

Un saludo muy cordial. Gracias de nuevo.
__________________
"Pedid y se os dará; buscad y hallaréis ..." (Lc 11,9-10)
"...si no tengo caridad, nada soy..." (1 Cor 13,1-13)

Última edición por jhonalone fecha: 19-11-2017 a las 20:25:05.
Responder Con Cita