how to fill a $n \times n$ "sign matrix" (entries $-1,0,1$) in order to get all distinct sum of lines and colums There is a set of matrices that are constructed subject to the following constraints:


*

*The matrix is a $S(n) \times S(n)$ matrix; 

*$S(n)$ is the sum of the first $n$ Fibonacci numbers $\pmod{m}$, that is $S(n) = (F_1 + F_2 +\ldots + F_n)\pmod{m}$ 

*The matrix contains only three kinds of integers $0,\ 1,\ -1$; 

*The sum of each row and each column in the matrix are all different. 
Here, the Fibonacci numbers are the numbers in the following sequence: $1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144,\ldots $
By definition, the first two Fibonacci numbers are $1$ and $1$, and each remaining number is the sum of the previous two. 
In mathematical terms, the sequence $F_n$ of Fibonacci numbers is defined by the recurrence relation $F_n = F_{n-1} + F_{n-2}$, with seed values $F_1 = F_2 = 1$. 
Given $n,m\in\Bbb Z$, your task is to construct the matrix. 
 A: In fact, the same question but without any reference to Fibonnacci sequence is a known issue whose solution has been published 25 years ago. Nevertheless, it provides a (positive) answer for even dimension but a negative answer in the case of odd dimensions (for example, no $7 \times 7$ such matrices can give all different sums).
Here are two references


*

*the main one here,

*with a development here.
The result is that there are solutions if and only if the matrix size $n$ is even ($n=2p$). In this case, the solutions are the $2n$ consecutive integers belonging to (integer) intervals $[1-n,n]$ or $[-n,n-1]$.
It is rather easy to find solutions in low dimensions by taking the following rules : 


*

*fill the (strictly) $\color{blue}{\text{upper triangular}}$ part of the matrix by $+1$s, do the same for the strict $\color{green}{\text{lower triangular}}$ part, this time with $-1$s.

*take for the $\color{red}{\text{diagonal values}}$ a sequence of $p=n/2$ numbers "$1$" followed by $p$ numbers "$0$" [Remark : it is not the unique way to obtain solutions : there are even a growing number of solutions as $n$ grows].
(It is easy to prove that these conditionx ensure to have a solution).
Here are examples of even size $n \times n$matrices with $n=4,6,8$ :
$$M_4=\left(\begin{array}{rrrr}\color{red}{1}&\color{blue}{1}&\color{blue}{1}& \ \ \color{blue}{1}\\ \color{green}{-1}&\color{red}{1}&\color{blue}{1}&\color{blue}{1}\\\color{green}{-1}&\color{green}{-1}&\color{red}{0}&\color{blue}{1}\\ \color{green}{-1}&\color{green}{-1}&\color{green}{-1}&\color{red}{0}\end{array}\right) \ \ \ \text{sums in} \ [-3,4]$$
$$M_6=\left(\begin{array}{rrrrrr}
1& 1& 1& 1& 1& \ \ 1\\
-1& 1& 1& 1& 1& 1\\
-1&-1& 1& 1& 1& 1\\
-1&-1&-1& 0& 1& 1\\
-1&-1&-1&-1&0& 1\\
-1&-1&-1&-1&-1& 0\end{array}\right) \ \ \ \text{sums in} \ [-5,6]$$
$$M_8=\left(\begin{array}{rrrrrr}
 0& 1& 1& 1& 1& 1& 1& \ \ 1\\
-1& 0& 1& 1& 1& 1& 1& 1\\
-1&-1& 1& 1& 1& 1& 1& 1\\
-1&-1&-1& 0& 1& 1& 1& 1\\
-1&-1&-1&-1& 1& 1& 1& 1\\
-1&-1&-1&-1&-1& 0& 1& 1\\
-1&-1&-1&-1&-1&-1& 1& 1\\
-1&-1&-1&-1&-1&-1&-1& 1\end{array}\right) \ \ \ \text{sums in} \ [-7,8]$$
(please note that for $M_8$, we have presented a different solution for the diagonal ; this solution has been obtained by the Matlab program below).
Remarks :  
1) From a single solution, many of them can be obtained by shuffling rows and/or columns, or  by applying rotations, transposition, or replacing the matrix by its opposite. This allows in particular to assume WLOG that the upper left entry can be taken equal to $1$ ; with the latter convention, all solutions have a common feature : they use a same number of $1$s and $0$s, i.e., without any entry $-1$.
2) Here is the Matlab program which has permitted to obtain these solutions and many others (for $n=2k$, one obtains the neat answer of $2^{k-1}$ solutions)
    clear all;close all;
    n=4;% matrix size
    M0=triu(ones(n),1)-triu(ones(n),1)';
    ns=0;% number of solutions
    b=3;
    for k=0:b^(n-1)-1
        d=[1,dec2base(k,b,n-1)-49];
        % base b=3 is used for digits 0,1,2 converted into -1,0,1
    M=M0+diag(d);
    s=sort([sum(M),sum(M')]);
    if all(diff(s)==1)
        ns=ns+1;fprintf('%1.0f',d);fprintf('\n');
    end;
    end;
    fprintf('n° of sol.: %d\n',ns)

