test Subroutine

recursive subroutine test(i, n)

each ? can be either a . or a # check pattern to match the int list

Arguments

Type IntentOptional Attributes Name
integer, intent(in) :: i
integer, intent(in) :: n

Calls

proc~~test~2~~CallsGraph proc~test~2 problem_12::test proc~test~2->proc~test~2 proc~match problem_12::match proc~test~2->proc~match

Called by

proc~~test~2~~CalledByGraph proc~test~2 problem_12::test proc~test~2->proc~test~2 proc~go~8 problem_12::go proc~go~8->proc~test~2 program~problem_12 problem_12 program~problem_12->proc~go~8

Source Code

    recursive subroutine test (i, n)
    !! each ? can be either a . or a #
    !! check pattern to match the int list

    integer, intent(in) :: i, n
    integer :: ix
    integer,dimension(*),parameter :: icoeffs = [POINT,NUMBER] !! set of coefficients ['.', '#']

    ! what we are not doing here is accounting for permutations
    ! that we know do not match, because the begin with a sequence
    ! that doesn't match. those need to be skipped...

    if (i > n) then
        ! so we have an array of 0s and 1s -> replace the 2s in the ipattern with these
        !     ipattern: 2220111  -> ???.###
        !            a: 011      -> .##
        !       result: 0110111  -> .##.###
        !write(*,'(a,1x,i5,1x, *(I1))') 'test:', iline, ipattern_tmp
        ipattern_tmp = unpack(a, mask=ipattern==QUESTION, field=ipattern)
        if (match(ipattern_tmp, ints)) n_valid = n_valid + 1
    else
        do ix = 1, 2
            a(i) = icoeffs(ix)
            call test(i+1, n)
        end do
    end if
    end subroutine test