Ver Mensaje Individual
  #5 (permalink)  
Antiguo 29/02/2008, 11:05
orochimaru15081986
 
Fecha de Ingreso: febrero-2008
Mensajes: 2
Antigüedad: 17 años, 2 meses
Puntos: 0
Re: Ayuda a convertir codigo PHP en ASP

hola a todos/as

tengo un problemilla con un programa en PHP que trata de un sudoku con opcion de resolver o de inicializar que tengo que pasar a ASP. el programa me funciona en principio pero no me resuelve cuando pulso el boton de resolver,os pongo el codigo por si alguien me pudiera ayudar a terminar el programa.

un saludo y gracias

codigo:

<%
'dim tablero
'dim sudoku
'dim i,j,x,y
%>
<html>
<head>
<title>SUDOKU DE MIGUEL</title>
</head>
<body>
<%
tablero = request.form("tablero")
sudoku = request.form("sudoku")

tablero = sudoku

function visualizar_form()
%>
<form action="sudoku2.asp" method="post">
<table>
<%for i = 0 to 8 %>
<tr>
<%for j = 0 to 8%>
<td>
<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='submit' name='boton' value='limpiar'>
</form>
<%
end function

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

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


function comprobar(x,y)
'dim correcto,a,b,contador

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

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

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
%>

<%
correcto = 1
for x = 0 to 8 and correcto
for y = 0 to 8 and correcto
correcto = comprobar(x,y)
next
NEXT

if boton = "resolver" then
if correcto then
response.write (resolver_sudoku(0,0))
else
response.write "datos de entrada incorrectos"
end if
end if

if boton = "limpiar" then
unset(sudoku)
unset(tablero)
end if

response.write (visualizar_form())



%>

</body>
</html>