Cody

# Problem 2653. Beauty of Parentheses

Solution 519359

Submitted on 2 Nov 2014 by Guillaume
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
%% str = '(()(()(()(()))))'; out = {'( )'; ' ()( ) '; ' ()( ) '; ' ()( ) '; ' () '} assert(isequal(braces(str),out))

out = '( )' ' ()( ) ' ' ()( ) ' ' ()( ) ' ' () ' bounds = 1 2 5 8 11 13 14 15 16 1 4 7 10 12 13 14 15 16

2   Pass
%% str = '()'; % trivial test out = {'()'}; assert(isequal(braces(str),out))

bounds = 1 2

3   Pass
%% str = '((((()))))'; out = {'( )'; ' ( ) '; ' ( ) '; ' ( ) '; ' () '} assert(isequal(braces(str),out))

out = '( )' ' ( ) ' ' ( ) ' ' ( ) ' ' () ' bounds = 1 2 3 4 5 7 8 9 10 1 2 3 4 6 7 8 9 10

4   Pass
%% a = randi(10); str = ''; for i = 1:a str = [str '()']; end out = {str}; assert(isequal(braces(str),out))

bounds = 1 2

5   Pass
%% str = '()(((())))()'; out = {'()( )()'; ' ( ) '; ' ( ) '; ' () '} assert(isequal(braces(str),out))

out = '()( )()' ' ( ) ' ' ( ) ' ' () ' bounds = 1 4 5 6 8 9 10 3 4 5 7 8 9 12

6   Pass
%% a = randi(10); str = ''; for i = 1:a str = ['(' str ')']; end out = {}; for i = 1:a s = [32*ones(1,i-1) '(' 32*ones(1,2*a-2*i) ')' 32*ones(1,i-1)]; out = [out; s]; end assert(isequal(braces(str),out))

bounds = 1 2 3 4 5 6 8 9 10 11 12 1 2 3 4 5 7 8 9 10 11 12