Program Pathways;
{William Wheeless
Enloe HS
Intermediate 5
March 23, 2006}
USES CRT;
TYPE
Lava=Array[1..5,1..5] of Char;
VAR
Grid:Lava;
x,y,x1,x2,y1,y2:Integer;
Procedure Input(VAR
Grid:Lava);
VAR
Nodes:String;
Begin
CLRSCR;
For x:=1 to 5 do
For y:=1 to 5 do
Grid[x,y]:=' ';
Writeln('Please input the coordinates of the nodes with no
seperation between the');
Writeln('numbers. Once the coordinates are complete, type
"00" at the end of the line.');
Readln(Nodes);
x:=1;
Repeat
VAL(Nodes[x],x1,y);
x:=x+1;
VAL(Nodes[x],y1,y);
x:=x+1;
If (x1=0) or (y1=0) then
Begin
Write(x1,',',y1,' is not a possible coordinate.
However, the program will continue to run.');
Readln;
End
Else Grid[x1,y1]:='X';
Until (Nodes[x]+Nodes[x+1]='00');
End;
Procedure Show(Grid:Lava);
Begin
For x:=1 to 5 do
For y:=1 to 5 do
Begin
Write(Grid[x,y],' ');
If (y=5) then
Writeln;
End;
End;
Function Paths(VAR
Temp:Lava;VAR x1,y1,x2,y2:Integer):Integer;
VAR
a,b,c,d,z,xup,xdown,yright,yleft:Integer;
Place:Lava;
Begin
If (Temp[x1,y1]<>'X') then
Paths:=0
Else if (x1=x2) and (y1=y2) then
Begin
Paths:=1;
Temp[x1,y1]:=' ';
End
Else
Begin
xup:=x1-1;
xdown:=x1+1;
yright:=y1+1;
yleft:=y1-1;
Temp[x1,y1]:=' ';
Place:=Temp;
a:=Paths(Place,xup,y1,x2,y2);
Place:=Temp;
b:=Paths(Place,xdown,y1,x2,y2);
Place:=Temp;
c:=Paths(Place,x1,yright,x2,y2);
Place:=Temp;
d:=Paths(Place,x1,yleft,x2,y2);
Paths:=a+b+c+d;
End;
End;
Procedure
Ask(Grid:Lava;x1,x2,y1,y2:Integer);
VAR
Temp:Lava;
Coords:String;
Begin
Writeln('Input the coordinates of the starting and ending
nodes with no seperations.');
Writeln('After each input, the number of paths will be
given.');
For x:=1 to 5 do
Begin
Temp:=Grid;
Readln(Coords);
VAL(Coords[1],x1,y);
VAL(Coords[2],y1,y);
VAL(Coords[3],x2,y);
VAL(Coords[4],y2,y);
If (x1=x2) and (y1=y2) then
Writeln('Those are the same point. No cycles are
allowed.')
Else if (Paths(Temp,x1,y1,x2,y2)=0) then
Writeln(' NONE')
Else
Begin
Temp:=Grid;
Writeln(' ',Paths(Temp,x1,y1,x2,y2));
End;
End;
End;
Begin
Input(Grid);
Show(Grid);
Ask(Grid,x1,x2,y1,y2);
Readln;
End.