%x:  0 1 2 3 4 5    % u:
f = [1 3 4 5 6 6;   %  1
     1 1 2 3 4 6]'; % -1

 r = [0 0 0 0 1 0;
     0 5 0 0 0 0]';
 
gamma = 0.5;

Q = 0*rand(6,2);
[m,n] = size(Q);

maxiter = 100;
epsilon = 0.001;

Qold = Q;
for i = 1 : maxiter,
%     i, Q(1:3,:), pause;
    Q(:) = gamma*max(Q(f,:),[],2); Q = Q + r;
    if max(max(abs(Q-Qold))) < epsilon, break; end;
    Qold = Q;
end;

Q
