China Naming Network - Auspicious day query - Matlab to achieve Joseph ring problem! ! Urgent! !
Matlab to achieve Joseph ring problem! ! Urgent! !
N = input ('total number of people:');
M=input ('Number of people who started to dequeue:');
num = 1:n; % nPeople are represented by1:n.
F = zero (1, n);
a = 1; % means there are always n people who need to go out.
j = 1; % is a number used to represent m times.
ind = 0; % corresponds to the subscript in num, that is, someone.
And a< = n.
And j< = m.
ind = ind+ 1;
If ind> length (number)
ind = 1;
end
j = j+ 1;
end
f(a)= num(ind); % keep the people in F to be eliminated.
Num(ind)=[]% Exclude this person.
ind = ind- 1; % rejected subscripts minus 1
j = 1;
a = a+ 1;
end
f