The squares of a 3×3 board are randomly coloured black or white. Let W be the number of white squares and B the number of black squares. The expected value of |B−W| can be expressed as ab where a and b are coprime positive integers. What is the value of a+b?

To find the expected value of |B−W|, we need to calculate the probability of each possible outcome and multiply it by the absolute difference between the number of black and white squares.

Let's consider the possible values of |B−W|. In a 3×3 board, the difference can be 0, 1, 2, 3, or 4.

1. When the difference is 0 (B = W), there can be 0 black and 0 white squares. There is only one possible outcome for this, so the probability is 1/2^9 = 1/512.

2. When the difference is 1 (|B−W| = 1), this can happen in two ways:
a) B = 5, W = 4: There are 5 black squares and 4 white squares. The number of ways this can happen is given by selecting 5 squares out of 9, which is 9 choose 5. So the probability is (9 choose 5)/2^9.
b) B = 4, W = 5: This is the reverse of case (a), so the probability is the same.

3. Similarly, when the difference is 2 (|B−W| = 2), this can happen in two ways:
a) B = 6, W = 4: There are 6 black squares and 3 white squares. The number of ways this can happen is (9 choose 6). So the probability is (9 choose 6)/2^9.
b) B = 4, W = 6: This is the reverse of case (a), so the probability is the same.

4. When the difference is 3 (|B−W| = 3), this can happen in two ways:
a) B = 7, W = 4: There are 7 black squares and 2 white squares. The number of ways this can happen is (9 choose 7). So the probability is (9 choose 7)/2^9.
b) B = 4, W = 7: This is the reverse of case (a), so the probability is the same.

5. When the difference is 4 (|B−W| = 4), there can be 8 black and 1 white square or 1 black and 8 white squares. Each case has a probability of (9 choose 8)/2^9.

Now, we can calculate the expected value:

E[|B−W|] = 0*(1/512) + 1*(2*(9 choose 5)/2^9) + 2*(2*(9 choose 6)/2^9) + 3*(2*(9 choose 7)/2^9) + 4*(2*(9 choose 8)/2^9).

Simplifying this expression, we get:

E[|B−W|] = 30/512.

Therefore, a = 30 and b = 512, and a + b = 542.

So, the value of a+b is 542.