I came across this one question in my textbook:
For each question on a multiple-choice test with 5 questions, there are five possible answers, of which exactly one is correct. If a student selects answers at random, give the probability that the first question answered correctly is question 4.
And I was wondering what would happen if the teacher also graded the test in a random order.
The way I approached the problem was by looking at a permutation of the sequence {1,2,3,4,5}. There's then a function that maps 1,2,3,4,5 to their position in the permutation we can call f.
The probability that the teacher grades in the order of that permutation and that question #4 is the first question right is then:
0.8^(f(4)-1)*0.2/(5!) since we need every question that were graded before #4 to be wrong and then for #4 to be right. The 1/5! is the probability that that specific grading order was chosen.
We can group the permutation functions by how they map 4. So the set of functions that map 4 to 1 would be one group and the set of functions that map 4 to 5 would be another group. There are 4! elements in each set (4! arrangements of 5 objects with one object being fixed) so the total probability is then
the sum from n=1 to 5 of 0.8^(n-1)*1/25 which I got to be roughly 0.134.
I think my answer is right but when I tried to check it experimentally in Python (simulating these probability problems makes for some good coding problems which is nice), I got 0.0711.
Here's the code:
import random
def experi():
li = [];
index = random.sample(range(1, 6), 5);
for i in range(1,6):
li.append(random.randint(1,6));
#check if 4th question is right if not, return 0
if li[3] != 1:
return 0;
#li is a list of random integers from 1-5
#for simplicity we assume that all questions have same answer, 1
#generate random integer, that is question number we need to get right first
#then we shuffle range(1:5) to get a random indexing
#we then iterate through the shuffle and check if first index to be right is 4
# goes through index if it hits 4 then nothing before was correct
#if it hits a right answer before 4, then we return false
for i in index:
if i == 3:
return 1;
if li[i-1] == 1:
return 0;
return 0;
count = 0;
N = 100000;
for i in range(N):
count += experi();
print(count/N);
I would really appreciate it if you guys could tell me whether it's my code or my math that's wrong (or both).