11
4
This challenge is partly an algorithms challenge, partly an optimization challenge and partly simply a fastest code challenge.
A T matrix is fully specified by its first row r
and first column c
. Each remaining element of the matrix is just a copy of the element that is diagonally up and left. That is M[i,j] = M[i-1,j-1]
. We will allow T matrices which are not square. We do however always assume that the number of rows is no more than the number of columns. For example, consider the following 3 by 5 T matrix.
10111
11011
11101
We say a matrix has property X if it contains two non-empty sets of columns with non-identical indices which have the same (vector) sum. The vector sum of one or more columns is simply an element-wise summation of their columns. That is the sum of two or more columns containing x
elements each is another column containing x
elements. The sum of one column is trivially the column itself.
The matrix above trivially has property X as the first and last columns are the same. The identity matrix never has property X.
If we just remove the last column of the matrix above then we get an example which does not have property X and would give a score of 4/3.
1011
1101
1110
The task
The task is to write code to find the highest scoring T matrix with binary entries and which does not have property X. For clarity, a matrix with binary entries has the property that each one of its entries is either 0 or 1.
Score
Your score will be the number columns divided by the number of rows in your best scoring matrix.
Tie Breaker
If two answers have the same score, the one submitted first wins.
In the (very) unlikely event that someone finds a method to get unlimited scores, the first valid proof of such a solution will be accepted. In the even more unlikely event that you can find a proof of optimality of a finite matrix I will of course award the win too.
Hint
All the answers at Find highest scoring matrix without property X are valid here but they are not optimal. There are T matrices without property X which are not cyclic.
For example, there is a 7 by 12 T matrix without property X but no such cyclic matrix.
21/11 would beat all the current answers from this and the previous challenge.
Languages and libraries
You can use any language which has a freely available compiler/interpreter/etc. for Linux and any libraries which are also freely available for Linux.
Bonus The first answer with a score greater than 2 gets an immediate 200 point bounty award. Ton Hospel has now achieved this!
Current leader board
- C++. Score 31/15 by Ton Hospel
- Java. Score 36/19 by Peter Taylor
- Haskell. Score 14/8 by alexander-brett
By the " two non-empty sets of columns with non-identical indices" you mean two sets of columns that are disjoint? Or, to rephrase this, is {1 ,3}, {1, 5} a valid two subsets of columns? – pawel.boczarski – 2015-04-26T10:52:26.117
@pawel.boczarski No not disjoint. Just non-identical. So {1 ,3}, {1, 5} is valid. – None – 2015-04-26T10:53:40.757
Ok. What about M[i,1] - is it a "borrow" from the last column of M[i-1] (zero is not a valid matrix column index)? And actually this is "up and left" rather than "up and right". – pawel.boczarski – 2015-04-26T10:58:23.620
@pawel.boczarski "right" was a typo. Thanks. The first row and column can be set to anything you like. They define the whole rest of the matrix. Does that answer your question? – None – 2015-04-26T13:13:55.537
Ok, I got it. It was my fault to not have read carefully that the first column is also defined. – pawel.boczarski – 2015-04-26T14:28:52.827
For the bonus, do you mean the *first* answer with a score greater than 2 gets 100 bounty? Otherwise that might cost you... :) – trichoplax – 2015-04-26T18:30:52.867
@trichoplax I do! – None – 2015-04-26T18:31:41.520
@Lembik: (continuing the comments from the now delted answer) As one particular sum of columns you consider the sum of all columns in a particular set S. Do you also allow the empty set S={} as one of those sets in your definition? This would just eliminate all matrices that contian a column that consists only of zeros. If i is the index of the said column, then the matrix would have the property X with the sets {},{i}. – flawr – 2015-04-27T18:32:32.020
@flawr No I don't allow the empty set (see the definition of property X). However we know that a matrix (with 2 or more columns) with a column consisting only of zeros always has property X in any case as that column plus any other column equals that other column. – None – 2015-04-27T18:34:39.173
Ah ok, well then it does not matter whether you allow the empty sum or not, except for the matrix 1x1 matrix 0=) – flawr – 2015-04-27T18:35:57.037
Is there any reason for calling the space of matrices T rather than Toeplitz? – Peter Taylor – 2015-04-28T14:08:21.677
@PeterTaylor No, not really. I was hoping for a pun involving T and X but in the end couldn't come up with a good one. – None – 2015-04-28T14:10:03.220
@Lembik: I'm having trouble fully understanding property X. Previously you state that any matrix containing a column of zeros because it is functionally an identity property. This indicates that the same column can appear in both sets. If I have column A which is some non-zero column, and column B which consists only of zeros, then the Matrix has property X because S1(A) = S2(A+B). So the "non-identical indices" property is met by any difference between the sets? Is the number of columns in each comparison set limited to 2, or can it be larger? – CChak – 2015-04-28T14:17:11.407
@CChak Yes the same column can appear in both sets. The two sets don't have to be disjoint, just not-identical (because that would trivially be uninteresting). The number of columns in each comparison set can be as large as you like. – None – 2015-04-28T14:24:15.540
@Lembik: Thanks for the quick response, but I hit return and it posted before I was done. The real question I was getting to was is there a limit on the number of columns in the summation set? or is it simply 1 or 2? I am assuming that each column index can be used once and only once per set. Again because that would make the problem uninteresting. – CChak – 2015-04-28T14:27:19.560
@CChak I also replied to that I think (after an edit). Is it clear now? – None – 2015-04-28T14:27:59.467
Yep. I've got it. thanks! – CChak – 2015-04-28T14:32:39.560
For the vector sum, since the matrix is binary, is the addition also performed in the binary system? For example, is
1 + 1 == 2
or1 + 1 == 0
? – Reto Koradi – 2015-05-10T21:37:40.390@RetroKoradi 1+1=2 – None – 2015-05-11T05:51:22.440