go Subroutine

subroutine go(puzzle, ileft, iskip)

compute the number of cols to left of mirror (0 if none) call with transpose(puzzle) to get number of rows above.

Arguments

Type IntentOptional Attributes Name
integer, intent(in), dimension(:,:) :: puzzle
integer, intent(out) :: ileft
integer, intent(in), optional :: iskip

don't consider this column


Called by

proc~~go~3~~CalledByGraph proc~go~3 problem_13::go program~problem_13 problem_13 program~problem_13->proc~go~3

Source Code

    subroutine go(puzzle, ileft, iskip)
    !! compute the number of cols to left of mirror (0 if none)
    !! call with transpose(puzzle) to get number of rows above.
    integer,dimension(:,:),intent(in) :: puzzle
    integer,intent(out) :: ileft
    integer,intent(in),optional :: iskip !! don't consider this column

    integer :: nrows, ncols, i, j
    logical :: mirror

    nrows = size(puzzle,1)
    ncols = size(puzzle,2)
    ileft = 0
    do i = 1, ncols-1
        if (present(iskip)) then
            if (i==iskip) cycle
        end if
        mirror = .true.
        do j = 1, min(i, ncols-i)
            if (any( puzzle(:,i-j+1) /= puzzle(:,i+j)) ) then
                mirror = .false.  ! no mirror on this line
                exit
            end if
        end do
        if (mirror) then
            ileft = i
            exit
        end if
    end do
    end subroutine go