How many houses have orange neighbors?

There are 10 houses in row. Each is colored randomly either orange, green, or blue.

What is the expected number of houses which have two orange neighbors?

As an example: in the image below are two such houses (marked with an X).


The answer is 0.8888888888888888.

This section requires Javascript.
You are seeing this because something didn't load right. We suggest you, (a) try refreshing the page, (b) enabling javascript if it is disabled on your browser and, finally, (c) loading the non-javascript version of this page . We're sorry about the hassle.

2 solutions

Finnley Paolella
Jun 18, 2020

The trick is to use indicator variables . Let a i = 1 a_i = 1 if the i t h i^{th} house has two orange neighbors and a i = 0 a_i = 0 if it doesn't. We are looking for: E ( a 2 + a 3 + + a 8 + a 9 ) E(a_2 + a_3 + \cdots + a_8 + a_9) We know E ( a i ) = 1 3 × 1 3 E(a_i) = \frac{1}{3} \times \frac{1}{3} , because there is 1 in 3 chance that the left house is orange and a 1 in 3 chance that the right house is orange. Because expected values are additive (even if they are correlated), we have: E ( a 2 + a 3 + + a 8 + a 9 ) = E ( a 2 ) + E ( a 3 ) + + E ( a 8 ) + E ( a 9 ) = 8 × 1 3 × 1 3 = 8 9 0.889 E(a_2 + a_3 + \cdots + a_8 + a_9) = E(a_2) + E(a_3) + \cdots + E(a_8) + E(a_9) = 8 \times \frac{1}{3} \times \frac{1}{3} = \frac{8}{9} \approx 0.889

Shouldn't you round it to 1 1 then?

A Former Brilliant Member - 11 months, 4 weeks ago

Log in to reply

No. The expected value does not need to be a value that possible. For example, the expected value for throwing a fair die is 3.5, even though there isn't a "3.5" on a die.

Finnley Paolella - 11 months, 4 weeks ago

Log in to reply

Ok. Thanks

A Former Brilliant Member - 11 months, 3 weeks ago

Great solution - thanks for sharing the problem.

Chris Lewis - 11 months, 4 weeks ago
Sahil Goyat
Jun 19, 2020
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
import random
k=['g','b','o']
s=0
n=100000
for i in range(1,n+1):
    c=0
    l=[]
    for j in range(0,10):
        l+=[random.choice(k)]
    for p in range(1,9):
        if l[p-1]=='o'==l[p+1]:
            c+=1
    s+=c
print(s/n)  

Hey Sahil, it seems to me that your code doesn't check the number of houses with two orange neighbors, but rather the number of times where three adjacent houses have the same color. Those expected values turn out to be the same, because the probability of three same-colored adjacent houses is also 1 9 \frac{1}{9} . Here is a python code which solves the "real" problem:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
from random import choice
s = 0
n = 100000
for i in range(n):
    l = []
    for j in range(10):
        l += [choice(['g', 'b', 'o'])]
    for p in range(1, 9):
        if l[p-1] == 'o' == l[p+1]:
            s += 1
print(s/n)

0.88635

Python is actually fast enough to solve the problem exactly in less than a second with the following code:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
from itertools import product

s = 0

for p in product((0,1,2), repeat=10):
    for i in range(1,9):
        if p[i-1]==0==p[i+1]:
            s+=1

print(s / 3**10)

0.8888888888888888

Finnley Paolella - 11 months, 3 weeks ago

Log in to reply

Thanks for correcting me.I didn't paid attention to that.

Sahil Goyat - 11 months, 3 weeks ago

0 pending reports

×

Problem Loading...

Note Loading...

Set Loading...