Cody

Problem 42307. Long-digit Subtraction

Solution 686742

Submitted on 13 Jun 2015
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   Fail
%% a = '99999'; b = '87654'; %---------- c = '12345'; assert(strcmp(long_digit_subtraction(a,b),c))

Requires string or character array input.

2   Fail
%% a = '99999'; b = '1234'; %---------- c = '98765'; assert(strcmp(long_digit_subtraction(a,b),c))

Requires string or character array input.

3   Fail
%% a = '99999'; b = '98765'; %---------- c = '1234'; assert(strcmp(long_digit_subtraction(a,b),c))

Requires string or character array input.

4   Fail
%% a = '99999'; b = '90909'; %---------- c = '9090'; assert(strcmp(long_digit_subtraction(a,b),c))

Requires string or character array input.

5   Fail
%% a = '11111'; b = '1234'; %---------- c = '9877'; assert(strcmp(long_digit_subtraction(a,b),c))

Requires string or character array input.

6   Fail
%% a = '10000'; b = '1'; %---------- c = '9999'; assert(strcmp(long_digit_subtraction(a,b),c))

Requires string or character array input.

7   Fail
%% a = '10000000'; b = '9999999'; %------------- c = '1'; assert(strcmp(long_digit_subtraction(a,b),c))

Requires string or character array input.

8   Fail
%% a = '100000000000000000000000000000000000000000000000000000000000000000000'; b = '1'; %-------------------------------------------------------------------------- c = '99999999999999999999999999999999999999999999999999999999999999999999'; assert(strcmp(long_digit_subtraction(a,b),c))

Requires string or character array input.

9   Fail
%% a = '2135476542136876516521651162516'; b = '165267982494266414654661818517'; %------------------------------------ c = '1970208559642610101866989343999'; assert(strcmp(long_digit_subtraction(a,b),c))

Requires string or character array input.

10   Fail
%% a = '1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000'; b = '1'; %------------------------------------------------------------------------------------------------------------------------------------------------------------------ c = '999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999'; assert(strcmp(long_digit_subtraction(a,b),c))

Requires string or character array input.

11   Fail
%% a = '1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000'; b = '1'; %------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ c = '999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999'; assert(strcmp(long_digit_subtraction(a,b),c))

Requires string or character array input.

12   Fail
%% switch randi(4) case 1 a = '99999'; b = '87654'; c = '12345'; case 2 a = '99999'; b = '1234'; c = '98765'; case 3 a = '10000000'; b = '9999999'; c = '1'; case 4 a = '99999'; b = '90909'; c = '9090'; end assert(strcmp(long_digit_subtraction(a,b),c))

Requires string or character array input.

13   Fail
%% switch randi(4) case 1 a = '99999'; b = '98765'; c = '1234'; case 2 a = '10000'; b = '1'; c = '9999'; case 3 a = '99999'; b = '87654'; c = '12345'; case 4 a = '2135476542136876516521651162516'; b = '165267982494266414654661818517'; c = '1970208559642610101866989343999'; end assert(strcmp(long_digit_subtraction(a,b),c))

Requires string or character array input.

14   Fail
%% switch randi(4) case 1 a = '11111'; b = '1234'; c = '9877'; case 2 a = '10000000'; b = '9999999'; c = '1'; case 3 a = '99999'; b = '98765'; c = '1234'; case 4 a = '99999'; b = '87654'; c = '12345'; end assert(strcmp(long_digit_subtraction(a,b),c))

Requires string or character array input.

Suggested Problems

More from this Author139

Community Treasure Hunt

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

Start Hunting!