# Test if aseq and bseq are adjacent in the 5x5 grid
# @param aseq The sequentialized representation of point a (0..24)
# @param bseq The sequentialized representation of point b (0..24)

isAdjVseq := proc(aseq, bseq)
    option remember;
    local prs ;
    prs := [ [0, 1], [1, 2], [2, 3],
    [3, 4], [4, 9], [9, 14], [14, 19], [18, 19],
    [17, 18], [16, 17], [11, 16], [11, 12],
    [12, 13], [8, 13], [7, 8], [6, 7],
    [5, 6], [5, 10], [10, 15], [15, 20],
    [20, 21], [21, 22], [22, 23], [23, 24] ] ;

    if [aseq, bseq] in prs then
        true;
    else
        false;
    end if;
end proc:

# Test whether points (a1, a2) and (b1, b2) are adjacent.
# @parm a1 horizontal coordinate of point a (0..4)
# @parm a2 vertical coordinate of point a (0..4)
# @parm b1 horizontal coordinate of point b (0..4)
# @parm b2 vertical coordinate of point b (0..4)

isAdjV := proc(a1, a2, b1, b2)
    option remember;
    local aseq, bseq ;

    # skip test if (a1, a2) = (b2, b2)
    if a1 = b1 and a2 = b2 then
        return true ;
    end if;

    # map the x and y coordinates to a unique representation (0..24)
    aseq := 5*a1+a2 ;
    bseq := 5*b1+b2 ;
    return isAdjVseq(min(aseq, bseq), max(aseq, bseq)) ;
end proc:

# Test whether integers a and b are adjacent as in Knuth's Amer. Math. Monthly Problem 11733
# @param a first integer
# @param b second integer

isKAdj := proc(a, b)
    # point is not adjacent to itselft
    if a = b then
        return false;
    end if;

    # obtain the two sequence of the base 5 digits
    a5 := convert(min(a, b), base, 5) ;
    b5 := convert(max(a, b), base, 5) ;

    # fill with zeros if the number of digits differs
    if nops(a5) < nops(b5) then
        a5 := [op(a5), seq(0, i=1..nops(b5)-nops(a5))] ;
    end if;
    isadj := true ;

    # test each pair of digits in the base-5 representation
    for j from 1 to nops(a5)-1 do
        for i from j+1 to nops(a5) do
            if  not isAdjV(op(i, a5), op(j, a5), op(i, b5), op(j, b5)) then
                return false;
            end if;
        end do:
    end do:
    return true ;
end proc:

A220952 := proc(n)
    option remember ;
    local a, nprev;
    if n =0 then
        0;
    else
        for a from 0 do
            if isKAdj(a, procname(n-1)) then
                known := false ;
                for nprev from 0 to n-1 do
                    if procname(nprev) = a then
                        known := true ;
                        break;
                    end if;
                end do:
                if not known then
                    return a;
                end if;
            end if;
        end do:
    end if;
end proc:

seq( A220952(n), n=0..100) ; # R. J. Mathar, Aug 25 2017