7
2
This is a version of this question which should not have such a straightforward solution and so should be more of an interesting coding challenge. It seems, for example, very likely there is no easy to find closed form solution, even though we have only increased the bound by one from the previous version. Having said that, you never know...
The Levenshtein distance between two strings is the minimum number of single character insertions, deletions, or substitutions to convert one string into the other one. Given a binary string \$S\$ of length \$n\$, we are a interested in the number of different strings of length \$n\$ which have distance at most \$4\$ from \$S\$.
For example, if \$S = 0000\$ there are four strings with Levenshtein distance exactly \$3\$ from \$S\$, six with distance exactly \$2\$, four with distance exactly \$1\$ and exactly one with distance \$0\$. This makes a total of \$15\$ distinct strings with distance at most \$3\$ from the string \$0000\$. The only string with distance exactly \$4\$ is \$1111\$.
For this task the input is a value of \$n \geq 4\$. Your code must output the average number of binary strings of length \$n\$ which have Levenshtein distance at most \$4\$ from a uniform and randomly sampled string \$S\$. Your answer can be output in any standard way you choose but it must be exact.
Examples
- n = 4. Average \$16\$.
- n = 5. Average 31 \$\frac{11}{16}\$.
- n = 6. Average 61 \$\frac{21}{32}\$.
- n = 7. Average 116 \$\frac{7}{8}\$.
- n = 8. Average 214 \$\frac{43}{128}\$.
- n = 9. Average 378 \$\frac{49}{246}\$.
- n = 10. Average 640 \$\frac{301}{512}\$.
- n = 11. Average 1042 \$\frac{1}{16}\$.
- n = 12. Average 1631 \$\frac{1345}{2048}\$.
- n = 13. Average 2466 \$\frac{3909}{4096}\$.
- n = 14. Average 3614 \$\frac{563}{8192}\$
Score
Your score is the highest value of \$n\$ you can reach in less than a minute on my linux box. If two answers get the same value then the first posted (or amended) wins. The timing is for each value separately.
My CPU is an Intel(R) Xeon(R) CPU X5460.
2less than a minute on my linux box - how are we to access your box for testing?
ssh
? we'll need an account ...could we come on over to yours? T_T – Noodle9 – 2020-01-15T13:58:10.6274@Noodle9 :) It's a standard thing for a [tag:fastest-code] competition to say what machine the testing will be done on. You should also state when you answer what you get on your PC of course. – Anush – 2020-01-15T14:11:32.110
1Doesn't this admit the same type of solution as the previous challenge, with a 25-state NFA instead of a 12-state NFA? – Nitrodon – 2020-01-15T18:56:54.230
@Nitrodon I am not sure but the person who answered the previous question suggested it wasn't so simple in the comments. – Anush – 2020-01-15T20:12:14.810
@Nitrodon Hadn't thought about the concrete number before, but yes, 25 states should be correct – Christian Sievers – 2020-01-15T21:04:45.710
I see a DFA with 266 states, and a matrix with complex eigenvalues. – Christian Sievers – 2020-01-17T19:48:48.587
@ChristianSievers Fascinating! But what does it mean? – Anush – 2020-01-17T20:12:16.540
1@Anush Closed formula contains trigonometric functions (or powers of complex numbers), or has to be written as depending on $n \mod k$ for, in this case, $k\in{3,4}$ (maybe not both are needed), – Christian Sievers – 2020-01-17T20:28:58.647