Cody

Problem 74. Balanced number

Solution 335063

Submitted on 17 Oct 2013 by Greg
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))

n = 13722 a = 13 b = 22 n2 = 0 n1 = 1 n2 = 2 n1 = 4 n2 = 4 tf = 1

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

n = 23567414 a = 2356 b = 7414 n2 = 0 n1 = 2 n2 = 7 n1 = 5 n2 = 11 n1 = 10 n2 = 12 n1 = 16 n2 = 16 tf = 1

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

n = 20567410 a = 2056 b = 7410 n2 = 0 n1 = 2 n2 = 7 n1 = 2 n2 = 11 n1 = 7 n2 = 12 n1 = 13 n2 = 12 tf = 0

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

n = 1 a = Empty string: 1-by-0 b = Empty string: 1-by-0 n2 = 0 tf = 1

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

n = 11111111 a = 1111 b = 1111 n2 = 0 n1 = 1 n2 = 1 n1 = 2 n2 = 2 n1 = 3 n2 = 3 n1 = 4 n2 = 4 tf = 1

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

n = 12345678 a = 1234 b = 5678 n2 = 0 n1 = 1 n2 = 5 n1 = 3 n2 = 11 n1 = 6 n2 = 18 n1 = 10 n2 = 26 tf = 0

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

n = 12333 a = 12 b = 33 n2 = 0 n1 = 1 n2 = 3 n1 = 3 n2 = 6 tf = 0

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

n = 9898 a = 98 b = 98 n2 = 0 n1 = 9 n2 = 9 n1 = 17 n2 = 17 tf = 1

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

n = 469200 a = 469 b = 200 n2 = 0 n1 = 4 n2 = 2 n1 = 10 n2 = 2 n1 = 19 n2 = 2 tf = 0

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

n = 57666 a = 57 b = 66 n2 = 0 n1 = 5 n2 = 6 n1 = 12 n2 = 12 tf = 1

Community Treasure Hunt

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

Start Hunting!