5
Consider \$3\$ binary strings of length \$n\$ chosen independently and uniformly at random. We are interested in computing the exact expected minimum Hamming distance between any pair. The Hamming distance between two strings of equal length is the number of positions at which the corresponding symbols are different.
Task
Given an input n between 2 and 10, inclusive, consider \$3\$ binary strings of length \$n\$ chosen independently and uniformly at random. Output the exact expected minimum Hamming distance between any pair.
Output should be given as a fraction.
Your code should run in TIO without timing out.
1Challenges should be self-contained: Please add the definition of Hamming Distance. – AlienAtSystem – 2020-01-31T19:10:00.797
I got slightly lost at the end, in the task section. You say "we sample" and then "compute the exact expected minimum hamming distance between any pair", but if we sampled, then there is no actual expectation, right? We just compute the Hamming distances? And then we output the minimum of the three? – RGS – 2020-01-31T19:44:54.843
@RGS Expected here means the mean average. I'll change the wording to make it clearer. Thank you. – Anush – 2020-01-31T19:52:03.753
Can you clarify what you mean by between any pair? Is that any of the three pairs once the three strings have been chosen? – Luis Mendo – 2020-01-31T20:02:41.173
4Could you please provide some test cases? – lolad – 2020-01-31T20:25:13.763
Also, do you actually have to generate the strings? Can you just choose a random value when comparing two characters? – lolad – 2020-01-31T20:48:28.273
@LuisMendo Yes that's right – Anush – 2020-01-31T21:01:27.333
@Anush Then please make it clear in the challenge text. People are not expected o read all comments – Luis Mendo – 2020-01-31T21:08:07.510
1
0.375, 0.75, 1.125, 1.5234375, 1.93505859375, ...? – Jonathan Allan – 2020-01-31T22:53:55.407Does "Output should be given as a fraction" mean decimals & floats are not allowed? (i.e. we should output a pair of integers) – Jonathan Allan – 2020-01-31T22:56:12.687
@JonathanAllan. The answer has to be exact. The easiest way is a pair of integers but you could also output a possibly recurring decimal if you prefer. – Anush – 2020-02-01T00:22:50.097
1The denominator will be a power of two, so the decimal will terminate. – Christian Sievers – 2020-02-01T00:42:34.753
I suggest the time restriction harder to miss in the spec, and tagging the challenge restricted-time. I suspect that the answers so far are too brute to meet the requirement. – xnor – 2020-02-01T00:55:38.337
I think the time limit is enough to stop fully brute forcing over the 2^30 triples of strings, but should allow setting one string to all zeroes, which doesn't affect the distribution, and brute forcing over the 2^20 values of the other two. I'd be interested to see faster methods. – xnor – 2020-02-01T01:04:04.480
1@xnor My code may have three loops, but it only iterates over the $n+3 \choose 3$ ways to write $n$ as a sum of four nonnegative integers. For $n=10$ that is 286 cases. – Christian Sievers – 2020-02-01T01:14:10.287
@ChristianSievers I missed that. What a nice method! I added a formula to your post. – xnor – 2020-02-01T01:50:41.633