\\ memoize! cache = Map() T(m,n,k) = { my (z=[m,n,k], v); if (!mapisdefined(cache, z, &v), mapput(cache, z, v=TT(m,n,k)); ); return (v); } f(a,b) = a TT(m,n,k) = { if (m==0, 1, my (nm=n%3, km=k%3, n0=n\3, k0=k\3, \\ n0\k0/0 1 2 \\ -----+------ \\ 0/a . . b \\ 1/. . * . \\ 2/. * . . \\ c . . d a = T(m-1,n0, k0), b = T(m-1,n0, k0+1), c = T(m-1,n0+1,k0), d = T(m-1,n0+1,k0+1)); if (nm==0 && km==0, a, nm==0 && km==1, f(a,b), nm==0 && km==2, f(b,a), nm==1 && km==0, f(a,c), nm==1 && km==1, f(a,d), nm==1 && km==2, a+b+d, \\ * nm==2 && km==0, f(c,a), nm==2 && km==1, a+c+d, \\ * nm==2 && km==2, f(d,a) ); ); } { i=-1; for (m=0, 4, my (w = 3^m + 1); for (n=0, w-1, for (k=0, n, v=T(m,n,k); print (i++ " " v); ); ); ); } quit