Question: Consider \$3\$ binary strings of length \$n\$ chosen independently and uniformly at random. We are interested in computing the exact expected minimum [Hamming distance](https://en.wikipedia.org/wiki/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](https://tio.run/#) without timing out.

Answer: 
[Pari/GP](http://pari.math.u-bordeaux.fr/), ~~92~~ 90 bytes
===========================================================

2 bytes saved thanks to @Nicolas!

```
n->sum(a=0,n,sum(b=0,n-a,sum(c=0,n-a-b,n!/a!/b!/c!/(n-a-b-c)!*min(a+b,min(a+c,b+c)))))/4^n

```

[Try it online!](https://tio.run/##JcpBCsMwDATAr8Q9KY2EEmiPzlMKksDBh6jGbd/vxokOu8OiIjXTVlqKzWn9/HaQOKNjl3aRnLbLpOiBJbAGtsBwTmRjuO/ZQSbFqw11srEfP17e0ruCxwWfM5aa/Qs@3AZaj0jgx1P7Aw "Pari/GP – Try It Online")

$$ f(n) = \frac{1}{4^n} \sum\_{\substack{a+b+c+d=n\\a,b,c,d\geq 0}} \binom{n}{a,b,c,d}\min(a+b,a+c,b+c)$$

A more direct brute force approach may be shorter in some languages, but I'm not sure if that's true for Pari. Anyway, it's a shame that Pari's `min` only accepts two arguments.

I can avoid the `min` and be about 6 times faster, but the compensating additional code makes it longer. Maybe in another language this is the shorter way. And maybe it is possible to simplify further and get rid of the innermost sum.

```
n->sum(a=0,n,sum(b=a,n-a,sum(c=b,n-a-b,n!/a!/b!/c!/(n-a-b-c)!*(a+b)*6/(1+(a==b)+(b==c))!)))/4^n

```

[Try it online!](https://tio.run/##HYxBCsMwDAS/EvUkxRZKoO1NeUpBNrjkUNW47ftdJ5dhWHa3Wtv5WXvR7rx9fi80XaLHw5JadLbTs6bDeRDEQBJIBsEz4kwwo4VE811wDeNCE4Wx10wERCTXh/fybui6xtsSa9v9iz5dJt4GCvoo9T8 "Pari/GP – Try It Online")
[05AB1E](https://github.com/Adriandmen/05AB1E/wiki/Commands), 26 [bytes](https://github.com/Adriandmen/05AB1E/wiki/Codepage)
============================================================================================================================

```
Ý4ãʒOQ}ε¨Ćü+ßI!*y!P÷}O4Im‚

```

Port of [*@JonathanAllan*'s Jelly answer](https://codegolf.stackexchange.com/a/198772/52210), which uses the same formula as [@ChristianSievers's Pari/GP answer](https://codegolf.stackexchange.com/a/198730/52210).  

Just like his answer, the output is not reduced to its simplest form.

[Try it online](https://tio.run/##ATEAzv9vc2FiaWX//8OdNMOjypJPUX3OtcKoxIbDvCvDn0khKnkhUMO3fU80SW3igJr//zEw) or [verify all test cases](https://tio.run/##AUYAuf9vc2FiaWX/MlTFuHZ5PyIg4oaSICI/ecKp/8OdNMOjypJPwq5Rfc61wqjEhsO8K8Ofwq4hKnkhUMO3fU80wq5t4oCa/yz/).

**Explanation:**

```python
Ý                 # Push a list in the range [0, (implicit) input-integer]
                  # (NOTE: Jonathan's Jelly answer uses the range [0,input) instead of
                  #  [0,input], but that doesn't pose an issue, since the mapped value will
                  #  result in 0, not affecting the total sum)
 4ã               # Create all possible quartets by using the cartesian product with 4
   ʒ              # Filter these quartets by:
    O             #  Take the sum
     Q            #  And check if it's equal to the (implicit) input-integer
   }ε             # After the filter: map each remaining quartet [a,b,c,d] to:
     ¨            #  Remove the last item d: [a,b,c]
      Ć           #  Enclose the list, appending its own head: [a,b,c,a]
       ü+         #  Sum each consecutive pair: [a+b,b+c,c+a]
         ß        #  Pop and push the minimum of this
          I!      #  Push the input, and take its factorial
            *     #  Multiply both by each other
             y!   #  Take the factorial of each value in the quartet: [a!,b!,c!,d!]
               P  #  Take the product of this: a!*b!*c!*d!
                ÷ #  Integer-divide the two: (min(a+b,b+c,c+a)*n!) // (a!*b!*c!*d!)
    }O            # After the map: take the sum of all values in the list
       I          # Push the input-integer again
      4 m         # And take 4 to the power this
         ‚        # And finally pair both together
                  # (after which this pair is output implicitly as result)

```