OFFSET
1,2
LINKS
Alois P. Heinz, Antidiagonals n = 1..100, flattened
EXAMPLE
1 2 7 6 23 10 ...
3 5 11 19 ...
4 13 12 ...
9 17 ...
8 ...
...
T(2,2) = 5 and its neighbors are 1, 2, 7, 11, 12, 13, 4 and 3, which are all coprime to 5.
MAPLE
iscoprime := proc(n, m) if gcd(n, m)=1 then RETURN(true); else RETURN(false); fi; end:
isin := proc(a, n, nmax) for row from 1 to nmax do for col from 1 to nmax do if a[row, col] = n then RETURN(true); end; od; od; RETURN(false); end:
iscoprMat := proc(a, candid, row, col, up) if not iscoprime(candid, a[row, col-1]) then RETURN(false); fi; if not iscoprime(candid, a[row-1, col]) then RETURN(false); fi; if not iscoprime(candid, a[row-1, col-1]) then RETURN(false); fi; if up then if not iscoprime(candid, a[row+1, col-1]) then RETURN(false); fi; else if not iscoprime(candid, a[row-1, col+1]) then RETURN(false); fi; fi; RETURN(true); end:
find := proc(a, row, col, nmax, up) for candid from 1 to 5000000 do if isin(a, candid, nmax) then next; fi; if not iscoprMat(a, candid, row, col, up) then next; fi; a[row, col] := candid; RETURN(a[row, col]); od; RETURN(-1); end:
nmax := 15; for row from 1 to nmax do for col from 1 to nmax do a[row, col] := -1; od : od : a[1, 1]:= 1 : up := false:
for dia from 2 to nmax do if up then for col from 1 to dia do row := dia+1-col; f := find(a, row, col, nmax, up); printf("%d, ", f); a[row, col] := f; od; else for row from 1 to dia do col := dia+1-row; f := find(a, row, col, nmax, up); printf("%d, ", f); a[row, col] := f; od; fi; up := not up : od : # R. J. Mathar, May 06 2006
MATHEMATICA
dmax = 12 (* number of antidiagonals *);
a[1, 1] = 1; used = {1}; a[_, _] = 1;
loop := For[i = d-j+1; k = 1, True, k++, If[FreeQ[used, k] && AllTrue[{ a[i-1, j+1], a[i-1, j], a[i-1, j-1], a[i, j-1], a[i+1, j-1]}, CoprimeQ[k, #]&], Sow[k]; AppendTo[used, k]; a[i, j] = k; Break[]]];
{1}~Join~Reap[Do[If[EvenQ[d], Do[loop, {j, d, 1, -1}], Do[loop, {j, 1, d}]], {d, 2, dmax}]][[2, 1]] (* Jean-François Alcover, Dec 14 2019 *)
CROSSREFS
AUTHOR
Amarnath Murthy, Apr 07 2003
EXTENSIONS
Edited by David Wasserman, Aug 09 2004
STATUS
approved