# Define the matrix
# States order: N, H, HH, T, TT, S
P = np.array([
[0, 1/2, 0, 1/2, 0, 0 ], # From N
[0, 0, 1/2, 1/2, 0, 0 ], # From H
[0, 0, 0, 1/2, 0, 1/2], # From HH
[0, 1/2, 0, 0, 1/2, 0 ], # From T
[0, 1/2, 0, 0, 0, 1/2], # From TT
[0, 0, 0, 0, 0, 1 ] # From S
])
the answer is 1- Prob(N to S state) with P^10
P^10 =
P^10 using Fractions:
['0/1', '55/1024', '17/512', '55/1024', '17/512', '423/512']
['0/1', '11/256', '7/256', '45/1024', '27/1024', '55/64']
['0/1', '27/1024', '17/1024', '7/256', '17/1024', '935/1024']
['0/1', '45/1024', '27/1024', '11/256', '7/256', '55/64']
['0/1', '7/256', '17/1024', '27/1024', '17/1024', '935/1024']
['0/1', '0/1', '0/1', '0/1', '0/1', '1/1']
so the answer is 1 - 423/512 = 89/512