Skip to content

Instantly share code, notes, and snippets.

@dpiponi
Last active August 25, 2025 21:17
Show Gist options
  • Save dpiponi/b2efcf754692664218000596966fbaff to your computer and use it in GitHub Desktop.
Save dpiponi/b2efcf754692664218000596966fbaff to your computer and use it in GitHub Desktop.
Count number of walks on lattice from (1, 1) to (1, 1) with winding number zero around (1/2, 1/2).
#include <iostream>
const long int N = 22;
long int table[N][1 + 2 * (N + 3) / 4][2 * N + 2][2 * N + 2] = {};
long int count(long int n, long int w, long int x, long int y)
{
long int in = n;
long int iw = w + 5;
long int ix = x + 20;
long int iy = y + 20;
if (table[in][iw][ix][iy] > 0)
{
return table[in][iw][ix][iy] - 1;
}
if (n == 0)
{
return w == 0 && x == 1 && y == 1;
}
long int t = 0;
t += count(n - 1, w, x - 2, y);
t += count(n - 1, w, x + 2, y);
if (x < 0 && y == 1)
{
t += count(n - 1, w, x, y + 2);
t += count(n - 1, w + 1, x, y - 2);
} else if (x < 0 && y == -1)
{
t += count(n - 1, w - 1, x, y + 2);
t += count(n - 1, w, x, y - 2);
return t;
} else
{
t += count(n - 1, w, x, y + 2);
t += count(n - 1, w, x, y - 2);
}
table[in][iw][ix][iy] = t + 1;
return t;
}
int main()
{
for (long int i = 4; i < N; i += 2)
{
std::cout << count(i, 0, 1, 1) << std::endl;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment