{ a = vector(10 000); h = vector(2 * #a); for (n = 1, #a, \\ mask of horizontal constraints th = 0; for (k=n, 2*n-1, th = bitor(th, h[k]); ); \\ mask of vertical constraints tv = if (n%2, 0, (2^(n/2)-1)*2^(a[n/2]-1)); ch = 2^0 + 2^n; cv = 2^n-1; for (w=1, oo, if (bitand(th, ch)==0 && bitand(tv, cv)==0, print (n " " a[n] = w); for (k=n, 2*n-1, h[k] += ch; ); break, ch *= 2; cv *= 2; ); ); ); } quit