Cody

Problem 3069. Pattern Recognition 2 - Known Unit Length, Various Array Length (including cell arrays)

Solution 2166068

Submitted on 19 Mar 2020 by Nikolaos Nikolaou
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
array = [1 2 3 1 2 3 1 2 3]; tf = 1; assert(isequal(pattern_recognition2(array),tf))

tf = logical 0 s = 1 2 3 1 2 3 1 2 3 s1 = 3 tf = logical 1 tf = logical 1

2   Pass
array = [1 2 2 1 2 2 1]; tf = 1; assert(isequal(pattern_recognition2(array),tf))

tf = logical 0 s = 1 2 2 1 2 2 s1 = 2 1 tf = logical 1

3   Pass
array = [1 2 1 2 2 2 1]; tf = 0; assert(isequal(pattern_recognition2(array),tf))

tf = logical 0 s = 1 2 1 1 2 1 s1 = 2 1

4   Pass
array = [1 10 100 1 10 100 1 10 100 1 10 100 1 10]; tf = 1; assert(isequal(pattern_recognition2(array),tf))

tf = logical 0 s = 1 10 100 1 10 100 1 10 100 1 10 100 s1 = 100 1 10 tf = logical 1

5   Pass
array = {'c3po','r2','d2','c3po','d2','r2','c3po','r2','d2','c3po'}; tf = 0; assert(isequal(pattern_recognition2(array),tf))

tf = logical 0 s = 1×9 cell array {'c3po'} {'r2'} {'d2'} {'c3po'} {'r2'} {'d2'} {'c3po'} {'r2'} {'d2'} s1 = 1×2 cell array {'d2'} {'c3po'}

6   Pass
array = 'hi hi hi hi'; tf = 1; assert(isequal(pattern_recognition2(array),tf))

tf = logical 0 s = 'hi hi hi ' s1 = ' hi' tf = logical 1

7   Pass
array = 'abcabcabcabcabcabcab'; tf = 1; assert(isequal(pattern_recognition2(array),tf))

tf = logical 0 s = 'abcabcabcabcabcabc' s1 = 'cab' tf = logical 1

8   Pass
array = {'c3po','r2','d2','c3po','r2','d2','c3po','r2','d2','c3po','r2'}; tf = 1; assert(isequal(pattern_recognition2(array),tf))

tf = logical 0 s = 1×9 cell array {'c3po'} {'r2'} {'d2'} {'c3po'} {'r2'} {'d2'} {'c3po'} {'r2'} {'d2'} s1 = 1×3 cell array {'d2'} {'c3po'} {'r2'} tf = logical 1

9   Pass
array = [1 2 3 3 2 3 1 2 3]; tf = 0; assert(isequal(pattern_recognition2(array),tf))

tf = logical 0 s = 1 2 3 1 2 3 1 2 3 s1 = 3

10   Pass
array = {'ab','cde','fg','ab','cbe','fg','ab','edc','fg'}; tf = 0; assert(isequal(pattern_recognition2(array),tf))

tf = logical 0 s = 1×9 cell array {'ab'} {'cde'} {'fg'} {'ab'} {'cde'} {'fg'} {'ab'} {'cde'} {'fg'} s1 = 1×1 cell array {'fg'}

11   Pass
array = 'abcabcabcabcabcabea'; tf = 0; assert(isequal(pattern_recognition2(array),tf))

tf = logical 0 s = 'abcabcabcabcabcabc' s1 = 'ea'

12   Pass
array = [1 10 100 1 100 10 1 10 100 1 10 100]; tf = 0; assert(isequal(pattern_recognition2(array),tf))

tf = logical 0 s = 1 10 100 1 10 100 1 10 100 1 10 100 s1 = 100

13   Pass
array = 'hi hi him'; tf = 0; assert(isequal(pattern_recognition2(array),tf))

tf = logical 0 s = 'hi hi hi ' s1 = 'm'

14   Pass
array = {'ab','cde','fg','ab','cde','fg','ab','cde','fg'}; tf = 1; assert(isequal(pattern_recognition2(array),tf))

tf = logical 0 s = 1×9 cell array {'ab'} {'cde'} {'fg'} {'ab'} {'cde'} {'fg'} {'ab'} {'cde'} {'fg'} s1 = 1×1 cell array {'fg'} tf = logical 1 tf = logical 1

15   Pass
ind = randi(4); switch ind case 1 array = {'c3po','r2','d2','c3po','r2','d2','c3po','r2','d2','c3po'}; tf = 1; case 2 array = 'hi hi him'; tf = 0; case 3 array = [1 2 3 3 2 3 1 2 3]; tf = 0; case 4 array = [1 2 2 1 2 2 1]; tf = 1; end assert(isequal(pattern_recognition2(array),tf))

tf = logical 0 s = 'hi hi hi ' s1 = 'm'

16   Pass
ind = randi(4); switch ind case 1 array = [1 2 3 3 2 3 1 2 3 1 2]; tf = 0; case 2 array = [1 10 100 1 100 10 1 10 100 1 10 100 1]; tf = 0; case 3 array = [1 2 2 1 2 2 1]; tf = 1; case 4 array = {'ab','cde','fg','ab','cde','fg','ab','cde','fg'}; tf = 1; end assert(isequal(pattern_recognition2(array),tf))

tf = logical 0 s = 1×9 cell array {'ab'} {'cde'} {'fg'} {'ab'} {'cde'} {'fg'} {'ab'} {'cde'} {'fg'} s1 = 1×1 cell array {'fg'} tf = logical 1 tf = logical 1

Suggested Problems

More from this Author139

Community Treasure Hunt

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

Start Hunting!