Cody

Problem 42307. Long-digit Subtraction

Solution 715431

Submitted on 15 Aug 2015 by Jean-Marie Sainthillier
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
%% a = '99999'; b = '87654'; %---------- c = '12345'; assert(strcmp(long_digit_subtraction(a,b),c))

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

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

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

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

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

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

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

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

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

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

12   Pass
%% 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))

13   Pass
%% 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))

14   Pass
%% 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))