cp's OEIS Frontend

This is a front-end for the Online Encyclopedia of Integer Sequences, made by Christian Perfect. The idea is to provide OEIS entries in non-ancient HTML, and then to think about how they're presented visually. The source code is on GitHub.

A387361 Number of 2n-step walks from (0, 0) to (0, 0) on square lattice with winding number zero around (1/2, 1/2).

Original entry on oeis.org

1, 4, 34, 360, 4240, 53184, 695462, 9366968, 128974482, 1806466376, 25649169360, 368251171264, 5336142742044, 77928806182640, 1145686661461166, 16941028325651416, 251769181131306246, 3758317957588392856, 56324288926707167928, 847084621934648027872, 12780033173479276354696
Offset: 0

Views

Author

Dan Piponi, Aug 27 2025

Keywords

Examples

			For n = 2 there are A002894(2) = 36 walks from (0, 0) to (0, 0). One walks around the unit square clockwise, the other counterclockwise, leaving a(2) = 34 with winding number zero.
		

Crossrefs

Programs

  • Maple
    f := proc(x, y, w, n) option remember;
    if abs(x) + abs(y) > n then return 0 fi;
    if n = 0 then if w = 0 then return 1 else return 0 fi fi;
    f(x + 1, y, w, n - 1) + f(x - 1, y, w, n - 1) +
    f(x, y + 1, ifelse(x < 1 and y = 0, w - 1, w), n - 1) +
    f(x, y - 1, ifelse(x < 1 and y = 1, w + 1, w), n - 1) end:
    a := n -> f(0, 0, 0, n): seq(a(n), n = 0..40, 2);  # Peter Luschny, Aug 29 2025
  • Mathematica
    f[x_,y_,w_,n_]:=f[x,y,w,n]=If[Abs[x]+Abs[y]>n,
      0,
      If[n==0,If[w==0,1,0],
        f[x+1,y,w,n-1]+
        f[x-1,y,w,n-1]+
        f[x,y+1,If[x<1&&y==0,w-1,w],n-1]+
        f[x,y-1,If[x<1&&y==1,w+1,w],n-1]]
    ];
    Table[f[0,0,0,n],{n,0,50,2}]
  • Python
    from functools import lru_cache
    @lru_cache(maxsize=None)
    def f(x: int, y: int, w: int, n: int) -> int:
        if abs(x) + abs(y) > n:
            return 0
        if n == 0:
            return 1 if w == 0 else 0
        return (
            f(x + 1, y, w, n - 1) +
            f(x - 1, y, w, n - 1) +
            f(x, y + 1, (w - 1) if (x < 1 and y == 0) else w, n - 1) +
            f(x, y - 1, (w + 1) if (x < 1 and y == 1) else w, n - 1)
        )
    print([f(0, 0, 0, n) for n in range(0, 50, 2)])