Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Solution 274636

Submitted on 6 Jul 2013 by Claudio Gelmi

Correct

38Size
Leading solution size is 24.
This solution is locked. To view this solution, you need to provide a solution of the same size or smaller.

Test Suite

Test
Code Input and Output
1
Pass
 
%%
% Fixed 6/21/13
n=40;
k=7;
s_expect=24;
survivor=solve_josephus(n,k);
assert(isequal(survivor,s_expect))

                    
2
Pass
 
%%
n=4;
k=2;
s_expect=1;
survivor=solve_josephus(n,k);
assert(isequal(survivor,s_expect))

                    
3
Pass
 
%%
n=40;
k=2;
s_expect=17;
survivor=solve_josephus(n,k);
assert(isequal(survivor,s_expect))

                    
4
Pass
 
%%
n=37;
k=6;
s_expect=10;
survivor=solve_josephus(n,k);
assert(isequal(survivor,s_expect))

                    
5
Pass
 
%%
n=29;
k=28;
s_expect=3;
survivor=solve_josephus(n,k);
assert(isequal(survivor,s_expect))

                    
6
Pass
 
%%
n=101;
k=1;
s_expect=101;
survivor=solve_josephus(n,k);
assert(isequal(survivor,s_expect))