Consider a binary string
S of length
n. Indexing from
1, we can compute the Hamming distances between
S[n-i..n] for all
i in order from
n-1. The Hamming distance between two strings of equal length is the number of positions at which the corresponding symbols are different. For example,
S = 01010
[0, 2, 0, 4, 0].
This is because
01 has Hamming distance two to
0101 has Hamming distance four to
1010 and finally
01010 matches itself.
We are only interested in outputs where the Hamming distance is at most 1, however. So in this task we will report a
Y if the Hamming distance is at most one and an
N otherwise. So in our example above we would get
[Y, N, Y, N, Y]
f(n) to be the number of distinct arrays of
Ns one gets when iterating over all
2^n different possible bit strings
S of length
n starting at
1, your code should output
n = 1..24, the correct answers are:
1, 1, 2, 4, 6, 8, 14, 18, 27, 36, 52, 65, 93, 113, 150, 188, 241, 279, 377, 427, 540, 632, 768, 870
Your code should iterate up from
n = 1 giving the answer for each
n in turn. I will time the entire run, killing it after two minutes.
Your score is the highest
n you get to in that time.
In the case of a tie, the first answer wins.
Where will my code be tested?
I will run your code on my (slightly old) Windows 7 laptop under cygwin. As a result, please give any assistance you can to help make this easy.
My laptop has 8GB of RAM and an Intel i7 5600U@2.6 GHz (Broadwell) CPU with 2 cores and 4 threads. The instruction set includes SSE4.2, AVX, AVX2, FMA3 and TSX.
Leading entries per language
- n = 40 in Rust using CryptoMiniSat, by Anders Kaseorg. (In Lubuntu guest VM under Vbox.)
- n = 35 in C++ using the BuDDy library, by Christian Seviers. (In Lubuntu guest VM under Vbox.)
- n = 34 in Clingo by Anders Kaseorg. (In Lubuntu guest VM under Vbox.)
- n = 31 in Rust by Anders Kaseorg.
- n = 29 in Clojure by NikoNyrh.
- n = 29 in C by bartavelle.
- n = 27 in Haskell by bartavelle
- n = 24 in Pari/gp by alephalpha.
- n = 22 in Python 2 + pypy by me.
- n = 21 in Mathematica by alephalpha. (Self reported)
I will now give a bounty of 200 points for any answer that gets up to n = 80 on my machine in two minutes.