hi i am trying to write a program to solve a sudoku puzzle. I have some problems when compiling the program can anyone help me pls.
the program is
Program Assignment3
implicit none
integer :: A(9,9), vanish, g,h,i,j,xs,ys,k,m
logical :: issolved
open(unit=20,file="sudoku.txt")
do g=1,9
read (20,*) (A(g,h),h=1,9)
end do
close(20)
issolved= .true.
do while (issolved)
issolved= .false.
do x=1,9
do y=1,9
if( A(x,y)>10) then
issolved= .true.
do j=1,9
if (A(x,j)<10) then
A(x,y)= vanish( A(x,y),A(x,j))
end if
end do
do i=1,9
if (A(i,y)<10) then
A(x,y)= vanish( A(x,y),A(i,y))
end if
end do
xs=(x-1)/3+1
ys=(y-1)/3+1
do k=(xs*3-2),(xs*3)
do m=(ys*3-2),(ys*3)
do m=1,9
if (A(x,m)<10) then
A(x,y)= vanish( A(x,y),A(x,m))
end if
end do
do k=1,9
if (A(k,y)<10) then
A(x,y)= vanish( A(x,y),A(k,y))
end if
end do
end do
end do
end if
end do
end do
do x=1,9
write(*,*) (A(x,y),y=1,9)
end do
end Program Assignment3
integer function vanish(s,r)
implicit none
integer ::no,temps,digit
integer ::s,r,u
temps=s
u=0
no=0
do while(temps>0)
digit= mod(temps,10)
temps= temps/10
if (digit/=r) then
no=no+digit*10**u
end if
end do
vanish=no
end function vanish
and the input file sudolu.txt contains
5 3 0 0 7 0 0 0 0
6 0 0 1 9 5 0 0 0
0 9 8 0 0 0 0 6 0
8 0 0 0 6 0 0 0 3
4 0 0 8 0 3 0 0 1
7 0 0 0 2 0 0 0 6
0 6 0 0 0 0 2 8 0
0 0 0 4 1 9 0 0 5
0 0 0 0 8 0 0 7 9
the program is
Program Assignment3
implicit none
integer :: A(9,9), vanish, g,h,i,j,xs,ys,k,m
logical :: issolved
open(unit=20,file="sudoku.txt")
do g=1,9
read (20,*) (A(g,h),h=1,9)
end do
close(20)
issolved= .true.
do while (issolved)
issolved= .false.
do x=1,9
do y=1,9
if( A(x,y)>10) then
issolved= .true.
do j=1,9
if (A(x,j)<10) then
A(x,y)= vanish( A(x,y),A(x,j))
end if
end do
do i=1,9
if (A(i,y)<10) then
A(x,y)= vanish( A(x,y),A(i,y))
end if
end do
xs=(x-1)/3+1
ys=(y-1)/3+1
do k=(xs*3-2),(xs*3)
do m=(ys*3-2),(ys*3)
do m=1,9
if (A(x,m)<10) then
A(x,y)= vanish( A(x,y),A(x,m))
end if
end do
do k=1,9
if (A(k,y)<10) then
A(x,y)= vanish( A(x,y),A(k,y))
end if
end do
end do
end do
end if
end do
end do
do x=1,9
write(*,*) (A(x,y),y=1,9)
end do
end Program Assignment3
integer function vanish(s,r)
implicit none
integer ::no,temps,digit
integer ::s,r,u
temps=s
u=0
no=0
do while(temps>0)
digit= mod(temps,10)
temps= temps/10
if (digit/=r) then
no=no+digit*10**u
end if
end do
vanish=no
end function vanish
and the input file sudolu.txt contains
5 3 0 0 7 0 0 0 0
6 0 0 1 9 5 0 0 0
0 9 8 0 0 0 0 6 0
8 0 0 0 6 0 0 0 3
4 0 0 8 0 3 0 0 1
7 0 0 0 2 0 0 0 6
0 6 0 0 0 0 2 8 0
0 0 0 4 1 9 0 0 5
0 0 0 0 8 0 0 7 9