Cody

# Problem 90. Connect Four Win Checker

Solution 2615707

Submitted on 26 Jun 2020 by 春樹 内糸
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   Pass
b = [0 1 1 0 2; 0 1 2 2 1; 1 0 2 2 2; 1 1 2 2 1; 1 1 2 1 0]; result_correct = 2; assert(isequal(c4winner(b),result_correct))

r = 5 c = 5 w = 0 w = 0 di = 1 0 1 1 0 1 -1 1 -1 0 -1 -1 0 -1 1 -1 pn = 1 2 ok = logical 1 pn = 2 2 pn = 3 2 ok = logical 0 pn = 1 2 ok = logical 1 pn = 2 3 ok = logical 0 pn = 1 2 ok = logical 1 pn = 1 3 pn = 1 4 ok = logical 0 pn = 1 2 ok = logical 1 pn = 0 3 ok = logical 0 pn = 1 2 ok = logical 1 pn = 0 2 ok = logical 0 pn = 1 2 ok = logical 1 pn = 0 1 ok = logical 0 pn = 1 2 ok = logical 1 pn = 1 1 ok = logical 0 pn = 1 2 ok = logical 1 pn = 2 1 ok = logical 0 w = 0 w = 0 di = 1 0 1 1 0 1 -1 1 -1 0 -1 -1 0 -1 1 -1 pn = 1 3 ok = logical 1 pn = 2 3 ok = logical 0 pn = 1 3 ok = logical 1 pn = 2 4 ok = logical 0 pn = 1 3 ok = logical 1 pn = 1 4 ok = logical 0 pn = 1 3 ok = logical 1 pn = 0 4 ok = logical 0 pn = 1 3 ok = logical 1 pn = 0 3 ok = logical 0 pn = 1 3 ok = logical 1 pn = 0 2 ok = logical 0 pn = 1 3 ok = logical 1 pn = 1 2 pn = 1 1 ok = logical 0 pn = 1 3 ok = logical 1 pn = 2 2 pn = 3 1 pn = 4 0 ok = logical 0 w = 0 w = 0 w = 0 w = 0 di = 1 0 1 1 0 1 -1 1 -1 0 -1 -1 0 -1 1 -1 pn = 1 5 ok = logical 1 pn = 2 5 ok = logical 0 pn = 1 5 ok = logical 1 pn = 2 6 ok = logical 0 pn = 1 5 ok = logical 1 pn = 1 6 ok = logical 0 pn = 1 5 ok = logical 1 pn = 0 6 ok = logical 0 pn = 1 5 ok = logical 1 pn = 0 5 ok = logical 0 pn = 1 5 ok = logical 1 pn = 0 4 ok = logical 0 pn = 1 5 ok = logical 1 pn = 1 4 ok = logical 0 pn = 1 5 ok = logical 1 pn = 2 4 pn = 3 3 pn = 4 2 ok = logical 0 w = 0 w = 0 w = 0 w = 0 di = 1 0 1 1 0 1 -1 1 -1 0 -1 -1 0 -1 1 -1 pn = 2 2 ok = logical 1 pn = 3 2 ok = logical 0 pn = 2 2 ok = logical 1 pn = 3 3 ok = logical 0 pn = 2 2 ok = logical 1 pn = 2 3 ok = logical 0 pn = 2 2 ok = logical 1 pn = 1 3 pn = 0 4 ok = logical 0 pn = 2 2 ok = logical 1 pn = 1 2 pn = 0 2 ok = logical 0 pn = 2 2 ok = logical 1 pn = 1 1 ok = logical 0 pn = 2 2 ok = logical 1 pn = 2 1 ok = logical 0 pn = 2 2 ok = logical 1 pn = 3 1 pn = 4 0 ok = logical 0 w = 0 w = 0 di = 1 0 1 1 0 1 -1 1 -1 0 -1 -1 0 -1 1 -1 pn = 2 3 ok = logical 1 pn = 3 3 pn = 4 3 pn = 5 3 w = 2 w = 2 result = 2

2   Pass
b = [0 0 0 0; 1 0 2 0; 1 1 1 1; 0 0 2 2]; result_correct = 1; assert(isequal(c4winner(b),result_correct))

r = 4 c = 4 w = 0 w = 0 w = 0 w = 0 w = 0 w = 0 w = 0 w = 0 di = 1 0 1 1 0 1 -1 1 -1 0 -1 -1 0 -1 1 -1 pn = 2 1 ok = logical 1 pn = 3 1 pn = 4 1 ok = logical 0 pn = 2 1 ok = logical 1 pn = 3 2 pn = 4 3 ok = logical 0 pn = 2 1 ok = logical 1 pn = 2 2 ok = logical 0 pn = 2 1 ok = logical 1 pn = 1 2 ok = logical 0 pn = 2 1 ok = logical 1 pn = 1 1 ok = logical 0 pn = 2 1 ok = logical 1 pn = 1 0 ok = logical 0 pn = 2 1 ok = logical 1 pn = 2 0 ok = logical 0 pn = 2 1 ok = logical 1 pn = 3 0 ok = logical 0 w = 0 w = 0 w = 0 w = 0 di = 1 0 1 1 0 1 -1 1 -1 0 -1 -1 0 -1 1 -1 pn = 2 3 ok = logical 1 pn = 3 3 ok = logical 0 pn = 2 3 ok = logical 1 pn = 3 4 ok = logical 0 pn = 2 3 ok = logical 1 pn = 2 4 ok = logical 0 pn = 2 3 ok = logical 1 pn = 1 4 ok = logical 0 pn = 2 3 ok = logical 1 pn = 1 3 ok = logical 0 pn = 2 3 ok = logical 1 pn = 1 2 ok = logical 0 pn = 2 3 ok = logical 1 pn = 2 2 ok = logical 0 pn = 2 3 ok = logical 1 pn = 3 2 ok = logical 0 w = 0 w = 0 w = 0 w = 0 di = 1 0 1 1 0 1 -1 1 -1 0 -1 -1 0 -1 1 -1 pn = 3 1 ok = logical 1 pn = 4 1 ok = logical 0 pn = 3 1 ok = logical 1 pn = 4 2 ok = logical 0 pn = 3 1 ok = logical 1 pn = 3 2 pn = 3 3 pn = 3 4 w = 1 w = 1 result = 1

3   Pass
b = [0 0 0 0 0 1; 2 2 0 0 2 2; 0 0 0 0 0 1; 2 0 0 1 1 0; 0 0 0 1 0 0; 0 0 1 0 2 2]; result_correct = 1; assert(isequal(c4winner(b),result_correct))

r = 6 c = 6 w = 0 w = 0 w = 0 w = 0 w = 0 w = 0 w = 0 w = 0 w = 0 w = 0 di = 1 0 1 1 0 1 -1 1 -1 0 -1 -1 0 -1 1 -1 pn = 1 6 ok = logical 1 pn = 2 6 ok = logical 0 pn = 1 6 ok = logical 1 pn = 2 7 ok = logical 0 pn = 1 6 ok = logical 1 pn = 1 7 ok = logical 0 pn = 1 6 ok = logical 1 pn = 0 7 ok = logical 0 pn = 1 6 ok = logical 1 pn = 0 6 ok = logical 0 pn = 1 6 ok = logical 1 pn = 0 5 ok = logical 0 pn = 1 6 ok = logical 1 pn = 1 5 ok = logical 0 pn = 1 6 ok = logical 1 pn = 2 5 ok = logical 0 w = 0 w = 0 di = 1 0 1 1 0 1 -1 1 -1 0 -1 -1 0 -1 1 -1 pn = 2 1 ok = logical 1 pn = 3 1 ok = logical 0 pn = 2 1 ok = logical 1 pn = 3 2 ok = logical 0 pn = 2 1 ok = logical 1 pn = 2 2 pn = 2 3 ok = logical 0 pn = 2 1 ok = logical 1 pn = 1 2 ok = logical 0 pn = 2 1 ok = logical 1 pn = 1 1 ok = logical 0 pn = 2 1 ok = logical 1 pn = 1 0 ok = logical 0 pn = 2 1 ok = logical 1 pn = 2 0 ok = logical 0 pn = 2 1 ok = logical 1 pn = 3 0 ok = logical 0 w = 0 w = 0 di = 1 0 1 1 0 1 -1 1 -1 0 -1 -1 0 -1 1 -1 pn = 2 2 ok = logical 1 pn = 3 2 ok = logical 0 pn = 2 2 ok = logical 1 pn = 3 3 ok = logical 0 pn = 2 2 ok = logical 1 pn = 2 3 ok = logical 0 pn = 2 2 ok = logical 1 pn = 1 3 ok = logical 0 pn = 2 2 ok = logical 1 pn = 1 2 ok = logical 0 pn = 2 2 ok = logical 1 pn = 1 1 ok = logical 0 pn = 2 2 ok = logical 1 pn = 2 1 pn = 2 0 ok = logical 0 pn = 2 2 ok = logical 1 pn = 3 1 ok = logical 0 w = 0 w = 0 w = 0 w = 0 w = 0 w = 0 di = 1 0 1 1 0 1 -1 1 -1 0 -1 -1 0 -1 1 -1 pn = 2 5 ok = logical 1 pn = 3 5 ok = logical 0 pn = 2 5 ok = logical 1 pn = 3 6 ok = logical 0 pn = 2 5 ok = logical 1 pn = 2 6 pn = 2 7 ok = logical 0 pn = 2 5 ok = logical 1 pn = 1 6 ok = logical 0 pn = 2 5 ok = logical 1 pn = 1 5 ok = logical 0 pn = 2 5 ok = logical 1 pn = 1 4 ok = logical 0 pn = 2 5 ok = logical 1 pn = 2 4 ok = logical 0 pn = 2 5 ok = logical 1 pn = 3 4 ok = logical 0 w = 0 w = 0 di = 1 0 1 1 0 1 -1 1 -1 0 -1 -1 0 -1 1 -1 pn = 2 6 ok = logical 1 pn = 3 6 ok = logical 0 pn = 2 6 ok = logical 1 pn = 3 7 ok = logical 0 pn = 2 6 ok = logical 1 pn = 2 7 ok = logical 0 pn = 2 6 ok = logical 1 pn = 1 7 ok = logical 0 pn = 2 6 ok = logical 1 pn = 1 6 ok = logical 0 pn = 2 6 ok = logical 1 pn = 1 5 ok = logical 0 pn = 2 6 ok = logical 1 pn = 2 5 pn = 2 4 ok = logical 0 pn = 2 6 ok = logical 1 pn = 3 5 ok = logical 0 w = 0 w = 0 w = 0 w = 0 w = 0 w = 0 w = 0 w = 0 w = 0 w = 0 w = 0 w = 0 di = 1 0 1 1 0 1 -1 1 -1 0 -1 -1 0 -1 1 -1 pn = 3 6 ok = logical 1 pn = 4 6 ok = logical 0 pn = 3 6 ok = logical 1 pn = 4 7 ok = logical 0 pn = 3 6 ok = logical 1 pn = 3 7 ok = logical 0 pn = 3 6 ok = logical 1 pn = 2 7 ok = logical 0 pn = 3 6 ok = logical 1 pn = 2 6 ok = logical 0 pn = 3 6 ok = logical 1 pn = 2 5 ok = logical 0 pn = 3 6 ok = logical 1 pn = 3 5 ok = logical 0 pn = 3 6 ok = logical 1 pn = 4 5 pn = 5 4 pn = 6 3 w = 1 w = 1 result = 1

4   Pass
b = [0 0 0 0; 1 0 0 0; 0 0 0 0; 0 0 0 2]; result_correct = 0; assert(isequal(c4winner(b),result_correct))

r = 4 c = 4 w = 0 w = 0 w = 0 w = 0 w = 0 w = 0 w = 0 w = 0 di = 1 0 1 1 0 1 -1 1 -1 0 -1 -1 0 -1 1 -1 pn = 2 1 ok = logical 1 pn = 3 1 ok = logical 0 pn = 2 1 ok = logical 1 pn = 3 2 ok = logical 0 pn = 2 1 ok = logical 1 pn = 2 2 ok = logical 0 pn = 2 1 ok = logical 1 pn = 1 2 ok = logical 0 pn = 2 1 ok = logical 1 pn = 1 1 ok = logical 0 pn = 2 1 ok = logical 1 pn = 1 0 ok = logical 0 pn = 2 1 ok = logical 1 pn = 2 0 ok = logical 0 pn = 2 1 ok = logical 1 pn = 3 0 ok = logical 0 w = 0 w = 0 w = 0 w = 0 w = 0 w = 0 w = 0 w = 0 w = 0 w = 0 w = 0 w = 0 w = 0 w = 0 w = 0 w = 0 w = 0 w = 0 w = 0 w = 0 w = 0 w = 0 di = 1 0 1 1 0 1 -1 1 -1 0 -1 -1 0 -1 1 -1 pn = 4 4 ok = logical 1 pn = 5 4 ok = logical 0 pn = 4 4 ok = logical 1 pn = 5 5 ok = logical 0 pn = 4 4 ok = logical 1 pn = 4 5 ok = logical 0 pn = 4 4 ok = logical 1 pn = 3 5 ok = logical 0 pn = 4 4 ok = logical 1 pn = 3 4 ok = logical 0 pn = 4 4 ok = logical 1 pn = 3 3 ok = logical 0 pn = 4 4 ok = logical 1 pn = 4 3 ok = logical 0 pn = 4 4 ok = logical 1 pn = 5 3 ok = logical 0 w = 0 w = 0 result = 0

5   Pass
b = [0 0 0 0; 1 1 1 1; 0 0 0 0; 0 0 0 2]; result_correct = 1; assert(isequal(c4winner(b),result_correct))

r = 4 c = 4 w = 0 w = 0 w = 0 w = 0 w = 0 w = 0 w = 0 w = 0 di = 1 0 1 1 0 1 -1 1 -1 0 -1 -1 0 -1 1 -1 pn = 2 1 ok = logical 1 pn = 3 1 ok = logical 0 pn = 2 1 ok = logical 1 pn = 3 2 ok = logical 0 pn = 2 1 ok = logical 1 pn = 2 2 pn = 2 3 pn = 2 4 w = 1 w = 1 result = 1

6   Pass
b = [0 0 2 2; 1 0 2 0; 1 2 2 1; 2 0 1 2]; result_correct = 2; assert(isequal(c4winner(b),result_correct))

r = 4 c = 4 w = 0 w = 0 w = 0 w = 0 di = 1 0 1 1 0 1 -1 1 -1 0 -1 -1 0 -1 1 -1 pn = 1 3 ok = logical 1 pn = 2 3 pn = 3 3 pn = 4 3 ok = logical 0 pn = 1 3 ok = logical 1 pn = 2 4 ok = logical 0 pn = 1 3 ok = logical 1 pn = 1 4 pn = 1 5 ok = logical 0 pn = 1 3 ok = logical 1 pn = 0 4 ok = logical 0 pn = 1 3 ok = logical 1 pn = 0 3 ok = logical 0 pn = 1 3 ok = logical 1 pn = 0 2 ok = logical 0 pn = 1 3 ok = logical 1 pn = 1 2 ok = logical 0 pn = 1 3 ok = logical 1 pn = 2 2 ok = logical 0 w = 0 w = 0 di = 1 0 1 1 0 1 -1 1 -1 0 -1 -1 0 -1 1 -1 pn = 1 4 ok = logical 1 pn = 2 4 ok = logical 0 pn = 1 4 ok = logical 1 pn = 2 5 ok = logical 0 pn = 1 4 ok = logical 1 pn = 1 5 ok = logical 0 pn = 1 4 ok = logical 1 pn = 0 5 ok = logical 0 pn = 1 4 ok = logical 1 pn = 0 4 ok = logical 0 pn = 1 4 ok = logical 1 pn = 0 3 ok = logical 0 pn = 1 4 ok = logical 1 pn = 1 3 pn = 1 2 ok = logical 0 pn = 1 4 ok = logical 1 pn = 2 3 pn = 3 2 pn = 4 1 w = 2 w = 2 result = 2

7   Pass
b = [0 0 0 0; 1 0 1 1; 0 0 2 0; 0 2 0 2]; result_correct = 0; assert(isequal(c4winner(b),result_correct))

r = 4 c = 4 w = 0 w = 0 w = 0 w = 0 w = 0 w = 0 w = 0 w = 0 di = 1 0 1 1 0 1 -1 1 -1 0 -1 -1 0 -1 1 -1 pn = 2 1 ok = logical 1 pn = 3 1 ok = logical 0 pn = 2 1 ok = logical 1 pn = 3 2 ok = logical 0 pn = 2 1 ok = logical 1 pn = 2 2 ok = logical 0 pn = 2 1 ok = logical 1 pn = 1 2 ok = logical 0 pn = 2 1 ok = logical 1 pn = 1 1 ok = logical 0 pn = 2 1 ok = logical 1 pn = 1 0 ok = logical 0 pn = 2 1 ok = logical 1 pn = 2 0 ok = logical 0 pn = 2 1 ok = logical 1 pn = 3 0 ok = logical 0 w = 0 w = 0 w = 0 w = 0 di = 1 0 1 1 0 1 -1 1 -1 0 -1 -1 0 -1 1 -1 pn = 2 3 ok = logical 1 pn = 3 3 ok = logical 0 pn = 2 3 ok = logical 1 pn = 3 4 ok = logical 0 pn = 2 3 ok = logical 1 pn = 2 4 pn = 2 5 ok = logical 0 pn = 2 3 ok = logical 1 pn = 1 4 ok = logical 0 pn = 2 3 ok = logical 1 pn = 1 3 ok = logical 0 pn = 2 3 ok = logical 1 pn = 1 2 ok = logical 0 pn = 2 3 ok = logical 1 pn = 2 2 ok = logical 0 pn = 2 3 ok = logical 1 pn = 3 2 ok = logical 0 w = 0 w = 0 di = 1 0 1 1 0 1 -1 1 -1 0 -1 -1 0 -1 1 -1 pn = 2 4 ok = logical 1 pn = 3 4 ok = logical 0 pn = 2 4 ok = logical 1 pn = 3 5 ok = logical 0 pn = 2 4 ok = logical 1 pn = 2 5 ok = logical 0 pn = 2 4 ok = logical 1 pn = 1 5 ok = logical 0 pn = 2 4 ok = logical 1 pn = 1 4 ok = logical 0 pn = 2 4 ok = logical 1 pn = 1 3 ok = logical 0 pn = 2 4 ok = logical 1 pn = 2 3 pn = 2 2 ok = logical 0 pn = 2 4 ok = logical 1 pn = 3 3 ok = logical 0 w = 0 w = 0 w = 0 w = 0 w = 0 w = 0 di = 1 0 1 1 0 1 -1 1 -1 0 -1 -1 0 -1 1 -1 pn = 3 3 ok = logical 1 pn = 4 3 ok = logical 0 pn = 3 3 ok = logical 1 pn = 4 4 pn = 5 5 ok = logical 0 pn = 3 3 ok = logical 1 pn = 3 4 ok = logical 0 pn = 3 3 ok = logical 1 pn = 2 4 ok = logical 0 pn = 3 3 ok = logical 1 pn = 2 3 ok = logical 0 pn = 3 3 ok = logical 1 pn = 2 2 ok = logical 0 pn = 3 3 ok = logical 1 pn = 3 2 ok = logical 0 pn = 3 3 ok = logical 1 pn = 4 2 pn = 5 1 ok = logical 0 w = 0 w = 0 w = 0 w = 0 w = 0 w = 0 di = 1 0 1 1 0 1 -1 1 -1 0 -1 -1 0 -1 1 -1 pn = 4 2 ok = logical 1 pn = 5 2 ok = logical 0 pn = 4 2 ok = logical 1 pn = 5 3 ok = logical 0 pn = 4 2 ok = logical 1 pn = 4 3 ok = logical 0 pn = 4 2 ok = logical 1 pn = 3 3 pn = 2 4 ok = logical 0 pn = 4 2 ok = logical 1 pn = 3 2 ok = logical 0 pn = 4 2 ok = logical 1 pn = 3 1 ok = logical 0 pn = 4 2 ok = logical 1 pn = 4 1 ok = logical 0 pn = 4 2 ok = logical 1 pn = 5 1 ok = logical 0 w = 0 w = 0 w = 0 w = 0 di = 1 0 1 1 0 1 -1 1 -1 0 -1 -1 0 -1 1 -1 pn = 4 4 ok = logical 1 pn = 5 4 ok = logical 0 pn = 4 4 ok = logical 1 pn = 5 5 ok = logical 0 pn = 4 4 ok = logical 1 pn = 4 5 ok = logical 0 pn = 4 4 ok = logical 1 pn = 3 5 ok = logical 0 pn = 4 4 ok = logical 1 pn = 3 4 ok = logical 0 pn = 4 4 ok = logical 1 pn = 3 3 pn = 2 2 ok = logical 0 pn = 4 4 ok = logical 1 pn = 4 3 ok = logical 0 pn = 4 4 ok = logical 1 pn = 5 3 ok = logical 0 w = 0 w = 0 result = 0

### Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!