Cody

# Problem 74. Balanced number

Solution 1181829

Submitted on 5 May 2017 by Jihye Sofia Seo
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
n = 13722; assert(isequal(isBalanced(n),true))

msg = 1 3 7 2 2 mylength = 5 index = 1 sum = 0 sum = 1 sum = -1 index = 2 sum = 2 sum = 0 index = 3 tf = logical 1

2   Pass
n = 23567414; assert(isequal(isBalanced(n),true))

msg = 2 3 5 6 7 4 1 4 mylength = 8 index = 1 sum = 0 sum = 2 sum = -2 index = 2 sum = 1 sum = 0 index = 3 sum = 5 sum = 1 index = 4 sum = 7 sum = 0 index = 5 tf = logical 1

3   Pass
n = 20567410; assert(isequal(isBalanced(n),false))

msg = 2 0 5 6 7 4 1 0 mylength = 8 index = 1 sum = 0 sum = 2 sum = 2 index = 2 sum = 2 sum = 1 index = 3 sum = 6 sum = 2 index = 4 sum = 8 sum = 1 index = 5 tf = logical 0

4   Pass
n = 1; assert(isequal(isBalanced(n),true))

msg = 1 mylength = 1 index = 1 sum = 0 tf = logical 1

5   Pass
n = 11111111; assert(isequal(isBalanced(n),true))

msg = 1 1 1 1 1 1 1 1 mylength = 8 index = 1 sum = 0 sum = 1 sum = 0 index = 2 sum = 1 sum = 0 index = 3 sum = 1 sum = 0 index = 4 sum = 1 sum = 0 index = 5 tf = logical 1

6   Pass
n = 12345678; assert(isequal(isBalanced(n),false))

msg = 1 2 3 4 5 6 7 8 mylength = 8 index = 1 sum = 0 sum = 1 sum = -7 index = 2 sum = -5 sum = -12 index = 3 sum = -9 sum = -15 index = 4 sum = -11 sum = -16 index = 5 tf = logical 0

7   Pass
n = 12333; assert(isequal(isBalanced(n),false))

msg = 1 2 3 3 3 mylength = 5 index = 1 sum = 0 sum = 1 sum = -2 index = 2 sum = 0 sum = -3 index = 3 tf = logical 0

8   Pass
n = 9898; assert(isequal(isBalanced(n),true))

msg = 9 8 9 8 mylength = 4 index = 1 sum = 0 sum = 9 sum = 1 index = 2 sum = 9 sum = 0 index = 3 tf = logical 1

9   Pass
n = 469200; assert(isequal(isBalanced(n),false))

msg = 4 6 9 2 0 0 mylength = 6 index = 1 sum = 0 sum = 4 sum = 4 index = 2 sum = 10 sum = 10 index = 3 sum = 19 sum = 17 index = 4 tf = logical 0

10   Pass
n = 57666; assert(isequal(isBalanced(n),true))

msg = 5 7 6 6 6 mylength = 5 index = 1 sum = 0 sum = 5 sum = -1 index = 2 sum = 6 sum = 0 index = 3 tf = logical 1

### Community Treasure Hunt

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

Start Hunting!