Longest binary sequence with no equal n-length subsequences

前端 未结 4 1959
耶瑟儿~
耶瑟儿~ 2020-12-10 20:34

We are looking for an algorithm with the following criteria.

Input is an arbitrary positive integer (n), that represents the length of the compare subse

4条回答
  •  执笔经年
    2020-12-10 21:15

    Using the free Minizinc constraint solver, you can write the search for a given sequence length as follows:

    int: n = 3;
    int: k = pow(2,n)+n-1;
    
    array[1..k] of var 0..1: a;
    
    constraint
      forall (i in 1..k-n) (
        forall (j in i+1..k-n+1) (
          exists (x in 0..n-1)(
            a[i+x] != a[j+x]
          )
        )
      );
    
    solve satisfy;
    
    output [show(a[m]) | m in 1..k];
    

    For n=3, the longest sequence is

    1110100011

    k=11 yields UNSATISFIABLE

    It took 71ms to find the sequence on k=10 bits for sub-sequence length n=3. For sub-sequence length n=9, the total sequence of 520 bits was found in 6.1s.

提交回复
热议问题