Cody

Problem 59. Pattern matching

Solution 2038145

Submitted on 28 Nov 2019 by dilek bulut
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
a = [0 1 1 0 -1 1 0 1 0 1 1 0 -1 1 0 1 0 1 0 0 -1 1 0 1 1 2 2 1 0 2 1 2]; b = [2 4]; out = matchPattern(a); assert(isequal(out(:), b(:)))

n = 0 1 1 0 -1 1 0 1 0 1 1 0 -1 1 0 1 0 1 0 0 -1 1 0 1 1 2 2 1 0 2 1 2 c = 0 1 1 0 -1 1 0 1 d = 0 1 0 1 0 1 1 2 g = -1 -1 -1 -1 h = 1 2 3 4 a = 0 1 1 0 -1 1 0 1 0 1 1 0 -1 1 0 1 0 1 0 0 -1 1 0 1 1 2 2 1 0 2 1 2 d = 1 1 1 1 1 0 2 2 g = 0 0 1 0 h = 1 2 4 a = 0 1 1 0 -1 1 0 1 0 1 1 0 -1 1 0 1 1 2 2 1 0 2 1 2 d = 1 0 1 0 2 1 g = 1 1 1 h = 1 2 3 a = 0 1 1 0 -1 1 0 1 0 1 1 0 -1 1 0 1 1 2 2 1 0 2 1 2 d = 0 -1 0 -1 1 0 g = 1 1 1 h = 1 2 3 a = 0 1 1 0 -1 1 0 1 0 1 1 0 -1 1 0 1 1 2 2 1 0 2 1 2 d = -1 1 -1 1 0 2 g = -2 -2 -2 h = 1 2 3 a = 0 1 1 0 -1 1 0 1 0 1 1 0 -1 1 0 1 1 2 2 1 0 2 1 2 d = 1 0 1 0 2 1 g = 1 1 1 h = 1 2 3 a = 0 1 1 0 -1 1 0 1 0 1 1 0 -1 1 0 1 1 2 2 1 0 2 1 2 d = 0 1 0 1 1 2 g = -1 -1 -1 h = 1 2 3 a = 0 1 1 0 -1 1 0 1 0 1 1 0 -1 1 0 1 1 2 2 1 0 2 1 2 son = 1 2 4 b = 2 4

2   Pass
a = [0 1 2 3 4 5 6 7 1 2 3 4 5 6 7 8 0 2 3 4 5 7 8 0 0 0 2 3 4 5 6 7]; b = [2]; out = matchPattern(a); assert(isequal(out(:), b(:)))

n = 0 1 2 3 4 5 6 7 1 2 3 4 5 6 7 8 0 2 3 4 5 7 8 0 0 0 2 3 4 5 6 7 c = 0 1 2 3 4 5 6 7 d = 0 1 1 2 0 2 0 0 g = -1 -1 -2 0 h = 1 2 3 a = 0 1 2 3 4 5 6 7 1 2 3 4 5 6 7 8 0 2 3 4 5 7 8 0 d = 1 2 2 3 2 3 g = -1 -1 -1 h = 1 2 3 a = 0 1 2 3 4 5 6 7 1 2 3 4 5 6 7 8 0 2 3 4 5 7 8 0 d = 2 3 3 4 3 4 g = -1 -1 -1 h = 1 2 3 a = 0 1 2 3 4 5 6 7 1 2 3 4 5 6 7 8 0 2 3 4 5 7 8 0 d = 3 4 4 5 4 5 g = -1 -1 -1 h = 1 2 3 a = 0 1 2 3 4 5 6 7 1 2 3 4 5 6 7 8 0 2 3 4 5 7 8 0 d = 4 5 5 6 5 7 g = -1 -1 -2 h = 1 2 3 a = 0 1 2 3 4 5 6 7 1 2 3 4 5 6 7 8 0 2 3 4 5 7 8 0 d = 5 6 6 7 7 8 g = -1 -1 -1 h = 1 2 3 a = 0 1 2 3 4 5 6 7 1 2 3 4 5 6 7 8 0 2 3 4 5 7 8 0 d = 6 7 7 8 8 0 g = -1 -1 8 h = 1 2 a = 0 1 2 3 4 5 6 7 1 2 3 4 5 6 7 8 son = 1 2 b = 2

3   Pass
a = [0 0 2 3 4 5 6 7 1 2 3 4 5 6 7 8 0 2 3 4 5 7 8 0 0 0 2 3 4 5 6 7]; b = [4]; out = matchPattern(a); assert(isequal(out(:), b(:)))

n = 0 0 2 3 4 5 6 7 1 2 3 4 5 6 7 8 0 2 3 4 5 7 8 0 0 0 2 3 4 5 6 7 c = 0 0 2 3 4 5 6 7 d = 0 0 1 2 0 2 0 0 g = 0 -1 -2 0 h = 1 4 a = 0 0 2 3 4 5 6 7 0 0 2 3 4 5 6 7 d = 0 2 0 2 g = -2 -2 h = 1 2 a = 0 0 2 3 4 5 6 7 0 0 2 3 4 5 6 7 d = 2 3 2 3 g = -1 -1 h = 1 2 a = 0 0 2 3 4 5 6 7 0 0 2 3 4 5 6 7 d = 3 4 3 4 g = -1 -1 h = 1 2 a = 0 0 2 3 4 5 6 7 0 0 2 3 4 5 6 7 d = 4 5 4 5 g = -1 -1 h = 1 2 a = 0 0 2 3 4 5 6 7 0 0 2 3 4 5 6 7 d = 5 6 5 6 g = -1 -1 h = 1 2 a = 0 0 2 3 4 5 6 7 0 0 2 3 4 5 6 7 d = 6 7 6 7 g = -1 -1 h = 1 2 a = 0 0 2 3 4 5 6 7 0 0 2 3 4 5 6 7 son = 1 4 b = 4

4   Pass
a = [0 0 2 3 4 5 6 7 1 2 3 4 5 6 7 8 0 2 3 4 5 7 8 0 0 0 12 13 140 150 160 1700]; b = [4]; out = matchPattern(a); assert(isequal(out(:), b(:)))

n = 0 0 2 3 4 5 6 7 1 2 3 4 5 6 7 8 0 2 3 4 5 7 8 0 0 0 12 13 140 150 160 1700 c = 0 0 2 3 4 5 6 7 d = 0 0 1 2 0 2 0 0 g = 0 -1 -2 0 h = 1 4 a = 0 0 2 3 4 5 6 7 0 0 12 13 140 150 160 1700 d = 0 2 0 12 g = -2 -12 h = 1 2 a = 0 0 2 3 4 5 6 7 0 0 12 13 140 150 160 1700 d = 2 3 12 13 g = -1 -1 h = 1 2 a = 0 0 2 3 4 5 6 7 0 0 12 13 140 150 160 1700 d = 3 4 13 140 g = -1 -127 h = 1 2 a = 0 0 2 3 4 5 6 7 0 0 12 13 140 150 160 1700 d = 4 5 140 150 g = -1 -10 h = 1 2 a = 0 0 2 3 4 5 6 7 0 0 12 13 140 150 160 1700 d = 5 6 150 160 g = -1 -10 h = 1 2 a = 0 0 2 3 4 5 6 7 0 0 12 13 140 150 160 1700 d = 6 7 160 1700 g = -1 -1540 h = 1 2 a = 0 0 2 3 4 5 6 7 0 0 12 13 140 150 160 1700 son = 1 4 b = 4

5   Pass
a = [0 1 1 0 1 2 3 4 1 5 5 3 2 3 4 5 6 7 7 9 -4 -1 -1 -12 5 6 9 10]; b = [3 6]; out = matchPattern(a); assert(isequal(out(:), b(:)))

n = 0 1 1 0 1 2 3 4 1 5 5 3 2 3 4 5 6 7 7 9 -4 -1 -1 -12 5 6 9 10 c = 0 1 1 0 d = 0 1 1 2 1 5 2 3 6 7 -4 -1 5 6 g = -1 -1 -4 -1 -1 -3 -1 h = 1 2 3 4 5 6 7 a = 0 1 1 0 1 2 3 4 1 5 5 3 2 3 4 5 6 7 7 9 -4 -1 -1 -12 5 6 9 10 d = 1 1 2 3 5 5 3 4 7 7 -1 -1 6 9 g = 0 -1 0 -1 0 0 -3 h = 1 3 5 6 a = 0 1 1 0 1 5 5 3 6 7 7 9 -4 -1 -1 -12 d = 1 0 5 3 7 9 -1 -12 g = 1 2 -2 11 h = 1 2 4 a = 0 1 1 0 1 5 5 3 -4 -1 -1 -12 son = 1 3 6 b = 3 6