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 3 X 3 rectangles have "floating" borders, so the constraint is actually equivalent to say that any element must be different from all neighbors in a Moore neighborhood of range 2 (having up to 5*5 = 25 grid points).
LINKS
Andrew Howroyd, Table of n, a(n) for n = 1..100
Eric Weisstein's World of Mathematics, Moore Neighborhood
EXAMPLE
For n = 4, the 4 X 4 grid is filled as follows (using hexadecimal digits):
[1 2 3 4]
[4 5 6 1]
[7 8 9 A]
[2 3 B 7], whence a(4) = # { 1, ..., 9, A, B} = 11.
For n = 8, the grid is filled as follows:
[1 2 3 4 5 6 7 8]
[4 5 6 1 2 3 9 A]
[7 8 9 A B C 1 2]
[2 3 C 7 4 5 6 B]
[5 1 D 2 3 8 A 4]
[6 4 8 9 1 D 2 3]
[3 7 A 5 6 B C 1]
[9 B 2 3 7 4 5 6], whence a(8) = # { 1, ..., 9, A, B, C, D } = 13.
For n = 5, 6 and 7, the solution is just the upper left n X n part of the above grid: all of these also require 13 symbols.
PROG
(PARI) a(n, m=3, 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)
m, S, N = 0, {1}, range(1, n+1)
g = [[0 for j in range(n+b)] for i in range(n+b)]
row, col = {i:set() for i in N}, {j:set() for j in N}
offsets = [(i, j) for i in range(-b+1, 1) for j in range(-b+1, 1)]
offsets += [(i, j) for i in range(-b+1, 0) for j in range(1, b)]
for i in N:
for j in N:
rect = set(g[i+o[0]][j+o[1]] for o in offsets)
e = min(S - row[i] - col[j] - rect)
g[i][j] = e
if e > m:
m = e
S.add(m+1)
row[i].add(e)
col[j].add(e)
return m
print([A292673(n) for n in range(1, 101)]) # Michael S. Branicky, Apr 13 2023
CROSSREFS
KEYWORD
nonn
AUTHOR
M. F. Hasler, Sep 20 2017
EXTENSIONS
Terms a(40) and beyond from Andrew Howroyd, Feb 22 2020
STATUS
approved