Cody

# Problem 44647. Win all the time!

Solution 1643106

Submitted on 11 Oct 2018
This solution is locked. To view this solution, you need to provide a solution of the same size or smaller.

### Test Suite

Test Status Code Input and Output
1   Fail
for i=1:1000 status=[10,10,10]; while sum(status)~=0 [Row_number, Num_of_lines] = remove_lines(status); if Num_of_lines>status(Row_number) disp('Error: Check number of lines'); result=false; break; end if Num_of_lines<1 disp('Error: You must remove at least one line'); result=false; break; end if Row_number~=1 && Row_number~=2 && Row_number~=3 disp('Error: Row number must be 1, 2 or 3.'); result=false; break; end if numel(Row_number)~=1 || numel(Num_of_lines)~=1 disp('Error: Row number must have one element'); result=false; break; end status(Row_number)=status(Row_number)-Num_of_lines; if sum(status)==0 disp('You lose'); result=false; break; end if sum(status)==1 disp('You win'); result=true; break; end [~,L]=max(status); status(L)=status(L)-randi(status(L)); if sum(status)==0 disp('You win'); result=true; break; end end res(i)=result; end number_of_wins= sum(res) assert(isequal(sum(res),1000))

d = 5 Row_number = 3 Num_of_lines = 4 You win d = 2 d = 1 Row_number = 3 Num_of_lines = 0 Error: You must remove at least one line d = 2 Row_number = 3 Num_of_lines = 1 You win d = 6 d = 3 Row_number = 3 Num_of_lines = 2 You win d = 8 d = 1 Row_number = 3 Num_of_lines = 0 Error: You must remove at least one line d = 3 d = 1 Row_number = 3 Num_of_lines = 0 Error: You must remove at least one line d = 7 d = 3 Row_number = 3 Num_of_lines = 2 You win d = 7 d = 3 d = 1 Row_number = 3 Num_of_lines = 0 Error: You must remove at least one line d = 1 Row_number = 3 Num_of_lines = 0 Error: You must remove at least one line d = 1 Row_number = 3 Num_of_lines = 0 Error: You must remove at least one line d = 9 d = 2 d = 1 Row_number = 3 Num_of_lines = 0 Error: You must remove at least one line d = 7 d = 6 Row_number = 3 Num_of_lines = 5 You win Row_number = 3 Num_of_lines = 9 You win d = 1 Row_number = 3 Num_of_lines = 0 Error: You must remove at least one line d = 8 d = 2 Row_number = 3 Num_of_lines = 1 You win d = 4 Row_number = 3 Num_of_lines = 3 You win Row_number = 3 Num_of_lines = 9 You win d = 8 Row_number = 3 Num_of_lines = 7 You win d = 7 d = 2 d = 1 Row_number = 3 Num_of_lines = 0 Error: You must remove at least one line Row_number = 3 Num_of_lines = 9 You win d = 6 d = 4 d = 2 Row_number = 3 Num_of_lines = 1 You win d = 8 d = 1 Row_number = 3 Num_of_lines = 0 Error: You must remove at least one line d = 8 d = 5 d = 1 Row_number = 3 Num_of_lines = 0 Error: You must remove at least one line d = 6 d = 1 Row_number = 3 Num_of_lines = 0 Error: You must remove at least one line d = 2 Row_number = 3 Num_of_lines = 1 You win d = 9 d = 8 d = 2 Row_number = 3 Num_of_lines = 1 You win d = 5 d = 1 Row_number = 3 Num_of_lines = 0 Error: You must remove at least one line d = 7 d = 5 d = 2 d = 1 Row_number = 3 Num_of_lines = 0 Error: You must remove at least one line d = 7 d = 6 d = 1 Row_number = 3 Num_of_lines = 0 Error: You must remove at least one line d = 3 Row_number = 3 Num_of_lines = 2 You win d = 4 Row_number = 3 Num_of_lines = 3 You win Row_number = 3 Num_of_lines = 9 You win d = 5 d = 3 Row_number = 3 Num_of_lines = 2 You win d = 5 Row_number = 3 Num_of_lines = 4 You win d = 1 Row_number = 3 Num_of_lines = 0 Error: You must remove at least one line d = 9 d = 3 d = 2 Row_number = 3 Num_of_lines = 1 You win d = 6 d = 1 Row_number = 3 Num_of_lines = 0 Error: You must remove at least one line Row_number = 3 Num_of_lines = 9 You win d = 9 d = 1 Row_number = 3 Num_of_lines = 0 Error: You must remove at least one line d = 5 d = 4 d = 2 Row_number = 3 Num_of_lines = 1 You win d = 7 d = 5 d = 3 d = 1 Row_number = 3 Num_of_lines = 0 Error: You must remove at least one line d = 8 Row_number = 3 Num_of_lines = 7 You win d = 4 d = 2 d = 1 Row_number = 3 Num_of_lines = 0 Error: You must remove at least one line d = 4 d = 1 Row_number = 3 Num_of_lines = 0 Error: You must remove at least one line d = 2 Row_number = 3 Num_of_lines = 1 You win d = 6 d = 4 d = 3 d = 2 Row_number = 3 Num_of_lines = 1 You win d = 9 d = 5 d = 1 Row_number = 3 Num_of_lines = 0 Error: You must remove at least one line Row_number = 3 Num_of_lines = 9 You win d = 8 d = 2 d = 1 Row_number = 3 Num_of_lines = 0 Error: You must remove at least one line d = 6 d = 5 d = 2 d = 1 Row_number = 3 Num_of_lines = 0 Error: You must remove at least one line d = 7 d = 4 d = 1 Row_number = 3 Num_of_lines = 0 Error: You must remove at least one line d = 1 Row_number = 3 Num_of_lines = 0 Error: You must remove at least one line d = 1 Row_number = 3 Num_of_lines = 0 Error: You must remove at least one line d = 9 d = 1 Row_number = 3 Num_of_lines = 0 Error: You must remove at least one line d = 8 d = 4 d = 2 Row_number = 3 Num_of_lines = 1 You win Row_number = 3 Num_of_lines = 9 You win d = 3 Row_number = 3 Num_of_lines = 2 You win Row_number = 3 Num_of_lines = 9 You win d = 2 Row_number = 3 Num_of_lines = 1 You win d = 8 d = 3 Row_number = 3 Num_of_lines = 2 You win d = 3 Row_number = 3 Num_of_lines = 2 You win d = 8 d = 1 Row_number = 3 Num_of_lines = 0 Error: You must remove at least one line d = 5 d = 3 Row_number = 3 Num_of_lines = 2 You win Row_number = 3 Num_of_lines = 9 You win d = 3 d = 1 Row_number = 3 Num_of_lines = 0 Error: You must remove at least one line d = 1 Row_number = 3 Num_of_lines = 0 Error: You must remove at least one line d = 4 Row_number = 3 Num_of_lines = 3 You win d = 9 d = 2 Row_number = 3 Num_of_lines = 1 You win d = 9 d = 7 Row_number = 3 Num_of_lines = 6 You win d = 9 d = 6 d = 2 Row_number = 3 Num_of_lines = 1 You win d = 1 Row_number = 3 Num_of_lines = 0 Error: You must remove at least one line d = 5 d = 2 d = 1 Row_number = 3 Num_of_lines = 0 Error: You must remove at least one line Row_number = 3 Num_of_lines = 9 You win d = 1 Row_number = 3 Num_of_lines = 0 Error: You must remove at least one line d = 5 d = 2 Row_number = 3 Num_of_lines = 1 You win d = 9 d = 2 d = 1 Row_number = 3 Num_of_lines = 0 Error: You must remove at least one line d = 2 d = 1 Row_number = 3 Num_of_lines = 0 Error: You must remove at least one line d = 3 d = 2 Row_number = 3 Num_of_lines = 1 You win Row_number = 3 Num_of_lines = 9 You win d = 3 Row_number = 3 Num_of_lines = 2 You win d = 9 Row_number = 3 Num_of_lines = 8 You win d = 6 Row_number = 3 Num_of_lines = 5 You win Row_number = 3 Num_of_lines = 9 You win d = 7 d = 5 d = 2 Row_number = 3 Num_of_lines = 1 You win d = 4 d = 2 Row_number = 3 Num_of_lines = 1 You win d = 4 d = 2 d = 1 Row_number = 3 Num_of_lines = 0 Error: You must remove at least one line d = 7 d = 6 d = 5 d = 2 Row_number = 3 Num_of_lines = 1 You win Row_number = 3 Num_of_lines = 9 You win d = 6 Row_number = 3 Num_of_lines = 5 You win d = 1 Row_number = 3 Num_of_lines = 0 Error: You must remove at least one line d = 6 d = 4 Row_number = 3 Num_of_lines = 3 You win d = 1 Row_number = 3 Num_of_lines = 0 Error: You must remove at least one line d = 7 d = 2 d = 1 Row_number = 3 Num_of_lines = 0 Error: You must remove at least one line d = 1 Row_number = 3 Num_of_lines = 0 Error: You must remove at least one line d = 7 d = 3 d = 2 Row_number = 3 Num_of_lines = 1 You win d = 9 d = 4 d = 1 Row_number = 3 Num_of_lines = 0 Error: You must remove at least one line d = 6 d = 3 d = 1 Row_number = 3 Num_of_lines = 0 Error: You must remove at least one line Row_number = 3 Num_of_lines = 9 You win d = 9 Row_number = 3 Num_of_lines = 8 You win d = 6 d = 2 d = 1 Row_number = 3 Num_of_lines = 0 Error: You must remove at least one line d = 9 d = 5 d = 4 Row_number = 3 Num_of_lines = 3 You win d = 4 d = 1 Row_number = 3 Num_of_lines = 0 Error: You must remove at least one line d = 8 d = 6 d = 2 Row_number = 3 Num_of_lines = 1 You win d = 8 d = 6 d = 4 Row_number = 3 Num_of_lines = 3 You win d = 6 d = 5 d = 2 d = 1 Row_number = 3 Num_of_l...

Assertion failed.