ASP - MI SUDOKU

   
Vista:

MI SUDOKU

Publicado por Rafael (1 intervención) el 06/03/2008 09:12:09
Muy buenas a tod@s,tengo un problema, hechenle un vistazo,me falla para Resolver.

<%option explicit

dim tablero
dim sudoku
dim i,j,x,y
%>

<html>
<body background="back03.JPG">
<div align="center">
<br><br>
<font size="+5" color="#FFFF00"><b>SUDOKU</b></font>

<%
tablero = request.form("tablero")
sudoku = request.form("sudoku")

tablero = sudoku

function visualizar_form()
%>
<br><br><br>
<form action="sudoku.asp" method="post">
<table border="3">
<%for i = 0 to 8 %>
<tr>
<%for j = 0 to 8%>
<td align="center">
<input type='text' size='1' maxlength='1' name='sudoku(" & "<%=i%>" & "," & "<%=j%>" & ")' value='0'>
</td>
<%next%>
</tr>
<%next%>
</table>
<input type='submit' name='boton' value='Resolver'>
<input type='reset' name='boton' value='Borrar'>
</form>
<%
end function
'==================================================================
'Imprimimos el sudoku
function imprimir_sudoku()
for x = 0 to 8
for y = 0 to 8
response.write request.form("sudoku(x,y)")
next
%>

<br>

<% next %>

<br>

<%
end function
'==================================================================================================
'Inicializamos
function inicializar(x,y)
dim a,b
a = x
b = y + 1

do while a < 9
if request.form("tablero(a,b)") = 0 then
request.form("sudoku(a,b)") = 0
b = b + 1
end if
if b > 8 then
b = 0
a = a + 1
end if
loop
end function
'====================================================================================================
'Comprobamos si es correcto lo realizado en el sudoku
function comprobar(x,y)

dim correcto,a,b,contador,retorno

correcto = 1

for a = 1 to 9 and correcto
contador = 0
for b = 0 to 8 and correcto
if request.form("sudoku(x,b)") <> 0 then
if request.form("sudoku(x,b)") = a then
contador = contador + 1
end if
end if
next
if contador > 1 then
correcto = 0
end if
next

retorno = correcto

if correcto then
for a = 1 to 9 and correcto
contador = 0
for b = 0 to 8 and correcto
if request.form("sudoku(b,y)") <> 0 then
if request.form("sudoku(b,y)") = a then
contador = contador + 1
end if
end if
next
if contador > 1 then
correcto = 0
end if
next
retorno = correcto
end if

dim x2,y2,c
if correcto then
for a = 1 to 9 and correcto
x2 = (x-(x mod 3))
y2 = (y-(y mod 3))
contador = 0
for b = x2 to (x2+3)-1
for c = y2 to (y2+3)-1
if request.form("sudoku(b,c)") <> 0 then
if request.form("sudoku(b,c)") = a then
contador = contador + 1
end if
end if
next
next
if contador > 1 then
correcto = 0
end if
next
retorno = correcto
end if
comprobar = retorno
end function
'=================================================================================
'Resolvemos el sudoku
function Resolver_sudoku(x,y)
if y > 8 then
y = 0
x = x + 1
end if
do while x < 9 and request.form("tablero(x,y)") <> 0
y = y + 1
if y > 8 then
y = 0
x = x + 1
end if
loop

if x = 9 then
if (not comprobar(8,8)) then
response.write "Sin solucion"
response.write("<br>")
end if
response.write (visualizar_form())
request.form("sudoku") = ""
request.form("tablero") = ""
response.End

else
for a = 1 to 9
response.write (inicializar(x,y))
request.form("sudoku(x,y)") = a
correcto = comprobar(x,y)
if correcto then
response.write (Resolver_sudoku(x,y+1))
else
request.form("sudoku(x,y)") = 0
end if
next
end if

end function
'=====================================================================================
dim correcto
correcto = 1

for x = 0 to 8 and correcto
for y = 0 to 8 and correcto
correcto = comprobar(x,y)
next
next

dim boton
if boton = "Resolver" then
if correcto then
response.write (Resolver_sudoku(0,0))
else
response.write ("Los datos de entrada son incorrectos")
end if
end if

'ESTO LO E DEJADO COMENTADO,YA QUE CON UN RESET LO HACE
'if boton = "Borrar" then
' unset(sudoku)
' unset(tablero)
'end if

response.write (visualizar_form())
%>
</div>
</body>
</html>
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
información
Otras secciones de LWP con contenido de ASP
- Código fuente de ASP
- Cursos de ASP
- Temas de ASP
información
Códigos de ASP
- Encuesta
- Control de acceso
- Grafico