OFFSET
1,2
COMMENTS
Consider the symbols as positive integers. By the greedy way we mean to fill the grid row by row from left to right always with the least possible positive integer such that the three constraints (on rows, columns and rectangular blocks) are satisfied.
In contrast to the sudoku case, the 2 X 2 rectangles have "floating" borders, so the constraint is actually equivalent to saying that any element must be different from all neighbors in a Moore neighborhood of range 1 (having up to 3*3=9 grid points).
LINKS
Michael S. Branicky, Table of n, a(n) for n = 1..1000 (terms 1..100 from Andrew Howroyd)
Eric Weisstein's World of Mathematics, Moore Neighborhood
EXAMPLE
For n = 4, the 4 X 4 grid is filled as follows:
[1 2 3 4]
[3 4 1 2]
[2 5 6 3]
[4 1 2 5], whence a(4) = 6.
For n = 3 the result would be the upper 3 X 3 part of the above grid, showing that also a(3) = 6.
PROG
(PARI) a(n, m=2, g=matrix(n, n))={my(ok(g, k, i, j, m)=if(m, ok(g[i, ], k)&&ok(g[, j], k)&&ok(concat(Vec(g[max(1, i-m+1)..i, max(1, j-m+1)..min(#g, j+m-1)])), k), !setsearch(Set(g), k))); for(i=1, n, for(j=1, n, for(k=1, n^2, ok(g, k, i, j, m)&&(g[i, j]=k)&&break))); vecmax(g)} \\ without "vecmax" the program returns the full n X n board.
(Python)
def a(n):
m, s, N = 0, {1}, range(1, n+1)
g = [[0 for j in range(n+2)] for i in range(n+2)]
row, col = {i:set() for i in N}, {j:set() for j in N}
for i in N:
for j in N:
rect = {g[i-1][j-1], g[i-1][j], g[i][j-1], g[i-1][j+1]}
e = min(s - row[i] - col[j] - rect)
g[i][j] = e
row[i].add(e)
col[j].add(e)
if e > m:
m = e
s.add(m+1)
return m
print([a(n) for n in range(1, 71)]) # Michael S. Branicky, Apr 13 2023
CROSSREFS
KEYWORD
nonn
AUTHOR
M. F. Hasler, Sep 20 2017
EXTENSIONS
Terms a(60) and beyond from Andrew Howroyd, Feb 22 2020
STATUS
approved