w max = 2500 hor = vector(2*w max + 1) dia = vector(#hor) ant = vector(#hor) len = [ 0, -1, 0, 0, 0, 0 ] dx = [ +2, +1, -1, -2, -1, +1 ] dy = [ 0, +1, +1, 0, -1, -1 ] n = -1; visit(x,y) = { my (h=w max + 1 + y); my (d=w max + 1 + (x+y)/2); my (a=w max + 1 + (x-y)/2); my (mask = bitor(hor[h], bitor(dia[d], ant[a]))); my (v = valuation(mask+1,2)); if (y<=0 && x==-y, print (n++ " " v); ); my (p=2^v); hor[h] += p; dia[d] += p; ant[a] += p; } { x = 0; y = 0; visit(x,y); for (w=1, w max, for (s=1, #len, for (i=1, w+len[s], x += dx[s]; y += dy[s]; visit(x,y); ); ); ); } quit