קוד:
<%@ Page Language="vb" Debug="true" %>
<script runat="server">
public class path
public moves as integer
public desc as string
end class
function f(Xpos as integer,Ypos as integer,board(,) as integer,NoOfMoves as integer,visited(,) as integer) as path
dim mypath as path=new path
'foundpath
if Xpos=4 and ypos=9
mypath.moves=NoOfMoves
mypath.desc=""
return(mypath)
end if
'circle path
if visited(xpos,ypos)=1
mypath.moves=999
mypath.desc="circle path"
return(mypath)
end if
dim temppath as path=new path
mypath.moves=999
if Xpos+board(Xpos,Ypos)<5
visited(xpos,ypos)=1
temppath=f(Xpos+board(Xpos,Ypos),Ypos,board,NoOfMo ves+1,visited)
visited(xpos,ypos)=0
if temppath.moves<mypath.moves
mypath.moves=temppath.moves
mypath.desc="move down"+ "<br>" + temppath.desc
end if
end if
if Ypos+board(Xpos,Ypos)<10
visited(xpos,ypos)=1
temppath=f(Xpos,Ypos+board(Xpos,Ypos),board,NoOfMo ves+1,visited)
visited(xpos,ypos)=0
if temppath.moves<mypath.moves
mypath.moves=temppath.moves
mypath.desc="move right"+ "<br>" +temppath.desc
end if
end if
if Xpos-board(Xpos,Ypos)>=0
visited(xpos,ypos)=1
temppath=f(Xpos-board(Xpos,Ypos),Ypos,board,NoOfMoves+1,visited)
visited(xpos,ypos)=0
if temppath.moves<mypath.moves
mypath.moves=temppath.moves
mypath.desc="move up"+ "<br>" +temppath.desc
end if
end if
if Ypos-board(Xpos,Ypos)>=0
visited(xpos,ypos)=1
temppath=f(Xpos,Ypos-board(Xpos,Ypos),board,NoOfMoves+1,visited)
visited(xpos,ypos)=0
if temppath.moves<mypath.moves
mypath.moves=temppath.moves
mypath.desc="move left"+ "<br>" +temppath.desc
end if
end if
return(mypath)
end function
Sub Page_Load(Sender As Object, E As EventArgs)
dim board(4,9) as integer
board(0,0)=3
board(0,1)=4
board(0,2)=2
board(0,3)=4
board(0,4)=1
board(0,5)=4
board(0,6)=7
board(0,7)=2
board(0,8)=4
board(0,9)=0
board(1,0)=2
board(1,1)=1
board(1,2)=1
board(1,3)=2
board(1,4)=6
board(1,5)=4
board(1,6)=8
board(1,7)=1
board(1,8)=5
board(1,9)=1
board(2,0)=3
board(2,1)=5
board(2,2)=1
board(2,3)=2
board(2,4)=5
board(2,5)=1
board(2,6)=2
board(2,7)=3
board(2,8)=2
board(2,9)=3
board(3,0)=7
board(3,1)=3
board(3,2)=4
board(3,3)=3
board(3,4)=4
board(3,5)=6
board(3,6)=3
board(3,7)=1
board(3,8)=4
board(3,9)=6
board(4,0)=1
board(4,1)=2
board(4,2)=4
board(4,3)=6
board(4,4)=8
board(4,5)=2
board(4,6)=3
board(4,7)=2
board(4,8)=5
board(4,9)=0
dim Visited(4,9) as integer
dim m as integer
dim n as integer
for m=0 to 4
for n=0 to 9
visited(m,n)=0
Response.Write(board(m,n))
Response.Write(" ")
next
Response.Write("<br>")
next
dim i as path=f(0,0,board,0,visited)
Response.Write(i.desc)
End Sub
</script>
<head>
</head>
<body>
</body>
</html>