clear all
% Happy Harry
P = [0,1/3,2/3;1/3,0,2/3;1,0,0];
v = [zeros(1,3),1] / [(P-eye(3)),ones(3,1)]
g = [20;30;40];
v * g
% simulazione
N = 10000;
i = 1;
w = zeros(1,3);
f = 0;
for n = 1:N
  w(i) = w(i)+1;
  f = f+g(i);
  i = randdisc(P(i,:));
end
w/N
f/N