Cody

Problem 74. Balanced number

Solution 2195117

Submitted on 6 Apr 2020 by Daniel Moreton
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))

nums = '13722' lenN = 5 split = 3 A = 0 B = 0 a = '13' b = '22' A = 1 B = 2 A = 4 B = 4 tf = logical 1

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

nums = '23567414' lenN = 8 split = 4 A = 0 B = 0 a = '2356' b = '7414' A = 2 B = 7 A = 5 B = 11 A = 10 B = 12 A = 16 B = 16 tf = logical 1

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

nums = '20567410' lenN = 8 split = 4 A = 0 B = 0 a = '2056' b = '7410' A = 2 B = 7 A = 2 B = 11 A = 7 B = 12 A = 13 B = 12 tf = logical 0

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

nums = '1' lenN = 1 split = 1 A = 0 B = 0 a = 1×0 empty char array b = 1×0 empty char array tf = logical 1

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

nums = '11111111' lenN = 8 split = 4 A = 0 B = 0 a = '1111' b = '1111' A = 1 B = 1 A = 2 B = 2 A = 3 B = 3 A = 4 B = 4 tf = logical 1

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

nums = '12345678' lenN = 8 split = 4 A = 0 B = 0 a = '1234' b = '5678' A = 1 B = 5 A = 3 B = 11 A = 6 B = 18 A = 10 B = 26 tf = logical 0

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

nums = '12333' lenN = 5 split = 3 A = 0 B = 0 a = '12' b = '33' A = 1 B = 3 A = 3 B = 6 tf = logical 0

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

nums = '9898' lenN = 4 split = 2 A = 0 B = 0 a = '98' b = '98' A = 9 B = 9 A = 17 B = 17 tf = logical 1

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

nums = '469200' lenN = 6 split = 3 A = 0 B = 0 a = '469' b = '200' A = 4 B = 2 A = 10 B = 2 A = 19 B = 2 tf = logical 0

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

nums = '57666' lenN = 5 split = 3 A = 0 B = 0 a = '57' b = '66' A = 5 B = 6 A = 12 B = 12 tf = logical 1

Suggested Problems

More from this Author95

Community Treasure Hunt

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

Start Hunting!