login
a(n) is the smallest number k that is the concatenation of the elements of a 3 X 3 matrix whose determinant is n and whose elements are a permutation of the numbers 1 through 9; a(n) = -1 if no such number k exists.
0

%I #32 Jun 03 2024 18:13:03

%S 123456789,123469857,123467589,123467895,123458769,123469578,

%T 123589476,123457689,123748569,123456798,123469587,123469875,

%U 123458967,123457986,123469785,123457698,123548769,123689574,123546789,123457896,123569487,123458697,123547689,123649758,123567498

%N a(n) is the smallest number k that is the concatenation of the elements of a 3 X 3 matrix whose determinant is n and whose elements are a permutation of the numbers 1 through 9; a(n) = -1 if no such number k exists.

%C The determinant of a 3 X 3 matrix whose elements are a permutation of the numbers 1..9 cannot exceed 412, so this sequence is finite.

%e a(0) = 123456789 because it is the smallest number that can be formed by concatenating the elements of a 3 X 3 matrix whose determinant is 0 and whose elements are a permutation of the numbers 1..9. The matrix is [1 2 3] [4 5 6] [7 8 9].

%t a[n_] := a[n] = Module[{mat}, mat = Select[Partition[#, 3] & /@ Permutations[Range[1, 9]], Det[#] == n &]; If[Length[mat] > 0, First[Sort[ToExpression[StringJoin[Riffle[ToString /@ Flatten[#], ""]]] & /@ mat]], 0]];

%t Monitor[(* Do not use Monitor[] if using Wolfram Cloud, otherwise memory issues may occur *)Table[a[n], {n, 0, 24}], {n, Table[a[m], {m, 0, n - 1}]}] (* _Robert P. P. McKone_, May 11 2024 *)

%o (Python)

%o from sympy import Matrix

%o from itertools import permutations

%o adict = dict()

%o for p in permutations(range(1, 10)):

%o v = Matrix(3, 3, p).det()

%o if v not in adict:

%o adict[v] = int("".join(map(str, p)))

%o afull = [adict[v] if v in adict else -1 for v in range(max(adict)+1)]

%o print(afull) # _Michael S. Branicky_, May 11 2024

%Y Cf. A085000, A088214, A088215, A221976.

%K base,fini,nonn,less

%O 0,1

%A _Jean-Marc Rebert_, May 11 2024