This is a front-end for the Online Encyclopedia of Integer Sequences, made by Christian Perfect. The idea is to provide OEIS entries in non-ancient HTML, and then to think about how they're presented visually. The source code is on GitHub.
%I A263542 #47 Sep 27 2024 20:55:00 %S A263542 24,112,376,768,2160,20352,5376,5904,86208,51840,64512,56736,1628352, %T A263542 1342656,44084736 %N A263542 Triangle T(M, N): Number of M X N matrices where 1<N<=M, all elements are distinct, all elements are at least 0 and at most M*N-1, and every 2 X 2 block of elements has the same sum. %C A263542 This sequence is given in this order: (2,2), (3,2), (3,3), (4,2), (4,3), (4,4), etc. %C A263542 The idea of the program below is that the first row, first column, and the (1,1)th element uniquely determine the rest of the matrix. Hence, all permutations of m+n integers in the range 0..m*n-1 are generated to fill the first row, first column, and (1,1). Then the empty spots in the matrix are filled in and if at any point a condition is violated (duplicate, < 0, >= M*N), the program immediately moves on to the next permutation. %C A263542 Much of the conversation in the main chat room of the Programming Puzzles and Code Golf Stack Exchange site - the Nineteenth Byte - following the linked message in the Links section deals with finding the terms of this sequence. %C A263542 Observation: at least the first 15 terms are divisible by 8. - _Omar E. Pol_, Oct 20 2015, Nov 21 2015 %C A263542 When M and N are both even, the block sum is 2(MN-1). When one or both is odd the block sum can vary: e.g., for M=N=3, it varies from 12 to 20. - _Peter J. Taylor_, Oct 21 2015 %C A263542 When M and N are both even, all solutions are toroidal: the block sums created by wrapping from the last column to the first column or the last row to the first row also equal 2(MN-1). When one of M or N is even, all solutions are cylindrical, with wrapping in the even dimension, but they are toroidal only in the trivial case of Odd X 2. When both M and N are odd, except in the trivial case of 1 X 1, solutions do not wrap in either direction. - _Peter J. Taylor_, Oct 21 2015 %H A263542 The Nineteenth Byte, <a href="http://chat.stackexchange.com/transcript/message/24811363#24811363">Originating chat message</a>, ChatRoom. %e A263542 One 3 X 3 solution (with a sum of 19) is: %e A263542 0 4 2 %e A263542 8 7 6 %e A263542 3 1 5 %e A263542 One 4 X 4 solution (with a sum of 30) is: %e A263542 0 3 4 7 %e A263542 12 15 8 11 %e A263542 1 2 5 6 %e A263542 13 14 9 10 %e A263542 One 5 X 5 solution (with a sum of 48) is: %e A263542 0 24 1 23 2 %e A263542 9 15 8 16 7 %e A263542 10 14 11 13 12 %e A263542 19 5 18 6 17 %e A263542 20 4 21 3 22 %e A263542 The triangle T(M, N) begins: %e A263542 M\N 2 3 4 5 6 ... %e A263542 2: 24 %e A263542 3: 112 376 %e A263542 4: 768 2160 20352 %e A263542 5: 5376 5904 86208 51840 %e A263542 6: 64512 56736 1628352 1342656 44084736 %e A263542 ...reformatted. - _Wolfdieter Lang_, Dec 16 2015 %o A263542 (Python) %o A263542 from itertools import permutations as P %o A263542 n = 4; m = 4; permutes = P(range(m*n), m+n); counter = 0 %o A263542 for p in permutes: %o A263542 grid = [p[:n]] %o A263542 for i in range(m-1): %o A263542 grid.append([p[n+i]]+[-1]*(n-1)) %o A263542 grid[1][1] = p[-1] %o A263542 s = p[0]+p[1]+p[n]+p[-1] %o A263542 has = list(p) %o A263542 fail = 0 %o A263542 for y in range(1,m): %o A263542 for x in range(1,n): %o A263542 if x == y == 1: continue %o A263542 r = s - (grid[y-1][x-1] + grid[y-1][x] + grid[y][x-1]) %o A263542 if r not in has and 0 <= r < m*n: %o A263542 grid[y][x]=r %o A263542 has.append(r) %o A263542 else: %o A263542 fail = 1 %o A263542 break %o A263542 if fail: break %o A263542 if not fail: %o A263542 counter += 1 %o A263542 print(counter) %K A263542 nonn,tabl,more %O A263542 2,1 %A A263542 _Lee Burnette_, Oct 20 2015