Re: Write a Fortran program to solve Sudoku puzzles :-)




"AN O'Nymous" <a_n_onymous80@xxxxxxxxxxx> wrote in message
news:1133795510.830786.177900@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
>>
> ! This section checks the validity of the rows/columns
> do i = 1,9
> count(i) = i
> enddo
>
> do i = 1, 9
> do k = 1, 9
> if (count(k) == sudoku_array(i,y)) then
> count(k) = 0
> endif
> enddo
> enddo
Might I suggest that once count(k) has been set 0 you can exit the 2 loops.
But the whole section is, I think, equivalent to (untested):

kount = ( (/ i, i = 1, 9 /) ) ! count is an intrinsic, so a name to be
avoided
do k = 1, 9
if(any(kount(k) == sudoku_array(:,y) ) ) kount(k) = 0 ! is y correct? do
you mean j?
end do

or even

where (kount == sudoku_array(:,y)) kount = 0

In my own code, I have found count, any and where invaluable.

Regards,

Mike Metcalf


.



Relevant Pages