Cody

# Problem 74. Balanced number

Solution 1779604

Submitted on 9 Apr 2019 by Yingao Zhang
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))

str = '13722' fst = '13' lst = '22' str = 4×1 cell array {0×0 char} {'1' } {'3' } {0×0 char} snum = 4 str = 4×1 cell array {0×0 char} {'2' } {'2' } {0×0 char} snum = 4 tf = logical 1

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

str = '23567414' fst = '2356' lst = '7414' str = 6×1 cell array {0×0 char} {'2' } {'3' } {'5' } {'6' } {0×0 char} snum = 16 str = 6×1 cell array {0×0 char} {'7' } {'4' } {'1' } {'4' } {0×0 char} snum = 16 tf = logical 1

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

str = '20567410' fst = '2056' lst = '7410' str = 6×1 cell array {0×0 char} {'2' } {'0' } {'5' } {'6' } {0×0 char} snum = 13 str = 6×1 cell array {0×0 char} {'7' } {'4' } {'1' } {'0' } {0×0 char} snum = 12 tf = logical 0

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

str = '1' fst = 1×0 empty char array lst = 1×0 empty char array str = 1×1 cell array {0×0 char} snum = 0 str = 1×1 cell array {0×0 char} snum = 0 tf = logical 1

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

str = '11111111' fst = '1111' lst = '1111' str = 6×1 cell array {0×0 char} {'1' } {'1' } {'1' } {'1' } {0×0 char} snum = 4 str = 6×1 cell array {0×0 char} {'1' } {'1' } {'1' } {'1' } {0×0 char} snum = 4 tf = logical 1

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

str = '12345678' fst = '1234' lst = '5678' str = 6×1 cell array {0×0 char} {'1' } {'2' } {'3' } {'4' } {0×0 char} snum = 10 str = 6×1 cell array {0×0 char} {'5' } {'6' } {'7' } {'8' } {0×0 char} snum = 26 tf = logical 0

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

str = '12333' fst = '12' lst = '33' str = 4×1 cell array {0×0 char} {'1' } {'2' } {0×0 char} snum = 3 str = 4×1 cell array {0×0 char} {'3' } {'3' } {0×0 char} snum = 6 tf = logical 0

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

str = '9898' fst = '98' lst = '98' str = 4×1 cell array {0×0 char} {'9' } {'8' } {0×0 char} snum = 17 str = 4×1 cell array {0×0 char} {'9' } {'8' } {0×0 char} snum = 17 tf = logical 1

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

str = '469200' fst = '469' lst = '200' str = 5×1 cell array {0×0 char} {'4' } {'6' } {'9' } {0×0 char} snum = 19 str = 5×1 cell array {0×0 char} {'2' } {'0' } {'0' } {0×0 char} snum = 2 tf = logical 0

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

str = '57666' fst = '57' lst = '66' str = 4×1 cell array {0×0 char} {'5' } {'7' } {0×0 char} snum = 12 str = 4×1 cell array {0×0 char} {'6' } {'6' } {0×0 char} snum = 12 tf = logical 1