Cody

# Problem 54. Maximum running product for a string of numbers

Solution 553127

Submitted on 7 Jan 2015 by Lukas
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
%% s = '123454321'; i_correct = 3; assert(isequal(running_product(s),i_correct))

current_numbers = 1 2 3 4 5 cum_prod = 1 2 6 24 120 current_numbers = 2 3 4 5 4 cum_prod = 2 6 24 120 480 current_numbers = 3 4 5 4 3 cum_prod = 3 12 60 240 720 current_numbers = 4 5 4 3 2 cum_prod = 4 20 80 240 480 current_numbers = 5 4 3 2 1 cum_prod = 5 20 60 120 120

2   Pass
%% s = '5820974944592307816406286208998628034825342117067'; i_correct = 28; assert(isequal(running_product(s),i_correct))

current_numbers = 5 8 2 0 9 cum_prod = 5 40 80 0 0 current_numbers = 8 2 0 9 7 cum_prod = 8 16 0 0 0 current_numbers = 2 0 9 7 4 cum_prod = 2 0 0 0 0 current_numbers = 0 9 7 4 9 cum_prod = 0 0 0 0 0 current_numbers = 9 7 4 9 4 cum_prod = 9 63 252 2268 9072 current_numbers = 7 4 9 4 4 cum_prod = 7 28 252 1008 4032 current_numbers = 4 9 4 4 5 cum_prod = 4 36 144 576 2880 current_numbers = 9 4 4 5 9 cum_prod = 9 36 144 720 6480 current_numbers = 4 4 5 9 2 cum_prod = 4 16 80 720 1440 current_numbers = 4 5 9 2 3 cum_prod = 4 20 180 360 1080 current_numbers = 5 9 2 3 0 cum_prod = 5 45 90 270 0 current_numbers = 9 2 3 0 7 cum_prod = 9 18 54 0 0 current_numbers = 2 3 0 7 8 cum_prod = 2 6 0 0 0 current_numbers = 3 0 7 8 1 cum_prod = 3 0 0 0 0 current_numbers = 0 7 8 1 6 cum_prod = 0 0 0 0 0 current_numbers = 7 8 1 6 4 cum_prod = 7 56 56 336 1344 current_numbers = 8 1 6 4 0 cum_prod = 8 8 48 192 0 current_numbers = 1 6 4 0 6 cum_prod = 1 6 24 0 0 current_numbers = 6 4 0 6 2 cum_prod = 6 24 0 0 0 current_numbers = 4 0 6 2 8 cum_prod = 4 0 0 0 0 current_numbers = 0 6 2 8 6 cum_prod = 0 0 0 0 0 current_numbers = 6 2 8 6 2 cum_prod = 6 12 96 576 1152 current_numbers = 2 8 6 2 0 cum_prod = 2 16 96 192 0 current_numbers = 8 6 2 0 8 cum_prod = 8 48 96 0 0 current_numbers = 6 2 0 8 9 cum_prod = 6 12 0 0 0 current_numbers = 2 0 8 9 9 cum_prod = 2 0 0 0 0 current_numbers = 0 8 9 9 8 cum_prod = 0 0 0 0 0 current_numbers = 8 9 9 8 6 cum_prod = 8 72 648 5184 31104 current_numbers = 9 9 8 6 2 cum_prod = 9 81 648 3888 7776 current_numbers = 9 8 6 2 8 cum_prod = 9 72 432 864 6912 current_numbers = 8 6 2 8 0 cum_prod = 8 48 96 768 0 current_numbers = 6 2 8 0 3 cum_prod = 6 12 96 0 0 current_numbers = 2 8 0 3 4 cum_prod = 2 16 0 0 0 current_numbers = 8 0 3 4 8 cum_prod = 8 0 0 0 0 current_numbers = 0 3 4 8 2 cum_prod = 0 0 0 0 0 current_numbers = 3 4 8 2 5 cum_prod = 3 12 96 192 960 current_numbers = 4 8 2 5 3 cum_prod = 4 32 64 320 960 current_numbers = 8 2 5 3 4 cum_prod = 8 16 80 240 960 current_numbers = 2 5 3 4 2 cum_prod = 2 10 30 120 240 current_numbers = 5 3 4 2 1 cum_prod = 5 15 60 120 120 current_numbers = 3 4 2 1 1 cum_prod = 3 12 24 24 24 current_numbers = 4 2 1 1 7 cum_prod = 4 8 8 8 56 current_numbers = 2 1 1 7 0 cum_prod = 2 2 2 14 0 current_numbers = 1 1 7 0 6 cum_prod = 1 1 7 0 0 current_numbers = 1 7 0 6 7 cum_prod = 1 7 0 0 0

3   Pass
%% s = '141592653589793238462643383279502884197169399399999'; i_correct = 47; assert(isequal(running_product(s),i_correct))

current_numbers = 1 4 1 5 9 cum_prod = 1 4 4 20 180 current_numbers = 4 1 5 9 2 cum_prod = 4 4 20 180 360 current_numbers = 1 5 9 2 6 cum_prod = 1 5 45 90 540 current_numbers = 5 9 2 6 5 cum_prod = 5 45 90 540 2700 current_numbers = 9 2 6 5 3 cum_prod = 9 18 108 540 1620 current_numbers = 2 6 5 3 5 cum_prod = 2 12 60 180 900 current_numbers = 6 5 3 5 8 cum_prod = 6 30 90 450 3600 current_numbers = 5 3 5 8 9 cum_prod = 5 15 75 600 5400 current_numbers = 3 5 8 9 7 cum_prod = 3 15 120 1080 7560 current_numbers = 5 8 9 7 9 cum_prod = 5 40 360 2520 22680 current_numbers = 8 9 7 9 3 cum_prod = 8 72 504 4536 13608 current_numbers = 9 7 9 3 2 cum_prod = 9 63 567 1701 3402 current_numbers = 7 9 3 2 3 cum_prod = 7 63 189 378 1134 current_numbers = 9 3 2 3 8 cum_prod = 9 27 54 162 1296 current_numbers = 3 2 3 8 4 cum_prod = 3 6 18 144 576 current_numbers = 2 3 8 4 6 cum_prod = 2 6 48 192 1152 current_numbers = 3 8 4 6 2 cum_prod = 3 24 96 576 1152 current_numbers = 8 4 6 2 6 cum_prod = 8 32 192 384 2304 current_numbers = 4 6 2 6 4 cum_prod = 4 24 48 288 1152 current_numbers = 6 2 6 4 3 cum_prod = 6 12 72 288 864 current_numbers = 2 6 4 3 3 cum_prod = 2 12 48 144 432 current_numbers = 6 4 3 3 8 cum_prod = 6 24 72 216 1728 current_numbers = 4 3 3 8 3 cum_prod = 4 12 36 288 864 current_numbers = 3 3 8 3 2 cum_prod = 3 9 72 216 432 current_numbers = 3 8 3 2 7 cum_prod = 3 24 72 144 1008 current_numbers = 8 3 2 7 9 cum_prod = 8 24 48 336 3024 current_numbers = 3 2 7 9 5 cum_prod = 3 6 42 378 1890 current_numbers = 2 7 9 5 0 cum_prod = 2 14 126 630 0 current_numbers = 7 9 5 0 2 cum_prod = 7 63 315 0 0 current_numbers = 9 5 0 2 8 cum_prod = 9 45 0 0 0 current_numbers = 5 0 2 8 8 cum_prod = 5 0 0 0 0 current_numbers = 0 2 8 8 4 cum_prod = 0 0 0 0 0 current_numbers = 2 8 8 4 1 cum_prod = 2 16 128 512 512 current_numbers = 8 8 4 1 9 cum_prod = 8 64 256 256 2304 current_numbers = 8 4 1 9 7 cum_prod = 8 32 32 288 2016 current_numbers = 4 1 9 7 1 cum_prod = 4 4 36 252 252 current_numbers = 1 9 7 1 6 cum_prod = 1 9 63 63 378 current_numbers = 9 7 1 6 9 cum_prod = 9 63 63 378 3402 current_numbers = 7 1 6 9 3 cum_prod = 7 7 42 378 1134 current_numbers = 1 6 9 3 9 cum_prod = 1 6 54 162 1458 current_numbers = 6 9 3 9 9 cum_prod = 6 54 162 1458 13122 current_numbers = 9 3 9 9 3 cum_prod = 9 27 243 2187 6561 current_numbers = 3 9 9 3 9 cum_prod = 3 27 243 729 6561 current_numbers = 9 9 3 9 9 cum_prod = 9 81 243 2187 19683 current_numbers = 9 3 9 9 9 cum_prod = 9 27 243 2187 19683 current_numbers = 3 9 9 9 9 cum_prod = 3 27 243 2187 19683 current_numbers = 9 9 9 9 9 cum_prod = 9 81 729 6561 59049

4   Pass
%% s = '7831652712019091456485669234603486104543266482133936072602'; i_correct = 21; assert(isequal(running_product(s),i_correct))

current_numbers = 7 8 3 1 6 cum_prod = 7 56 168 168 1008 current_numbers = 8 3 1 6 5 cum_prod = 8 24 24 144 720 current_numbers = 3 1 6 5 2 cum_prod = 3 3 18 90 180 current_numbers = 1 6 5 2 7 cum_prod = 1 6 30 60 420 current_numbers = 6 5 2 7 1 cum_prod = 6 30 60 420 420 current_numbers = 5 2 7 1 2 cum_prod = 5 10 70 70 140 current_numbers = 2 7 1 2 0 cum_prod = 2 14 14 28 0 current_numbers = 7 1 2 0 1 cum_prod = 7 7 14 0 0 current_numbers = 1 2 0 1 9 cum_prod = 1 2 0 0 0 current_numbers = 2 0 1 9 0 cum_prod = 2 0 0 0 0 current_numbers = 0 1 9 0 9 cum_prod = 0 0 0 0 0 current_numbers = 1 9 0 9 1 cum_prod = 1 9 0 0 0 current_numbers = 9 0 9 1 4 cum_prod = 9 0 0 0 0 current_numbers = 0 9 1 4 5 cum_prod = 0 0 0 0 0 current_numbers = 9 1 4 5 6 cum_prod = 9 9 36 180 1080 current_numbers = 1 4 5 6 4 cum_prod = 1 4 20 120 480 current_numbers = 4 5 6 4 8 cum_prod = 4 20 120 480 3840 current_numbers = 5 6 4 8 5 cum_prod = 5 30 120 960 4800 current_numbers = 6 4 8 5 6 cum_prod = 6 24 192 960 5760 current_numbers = 4 8 5 6 6 cum_prod = 4 32 160 960 5760 current_numbers = 8 5 6 6 9 cum_prod = 8 40 240 1440 12960 current_numbers = 5 6 6 9 2 cum_prod = 5 30 180 1620 3240 current_numbers = 6 6 9 2 3 cum_prod = 6 36 324 648 1944 current_numbers = 6 9 2 3 4 cum_prod = 6 54 108 324 1296 current_numbers = 9 2 3 4 6 cum_prod = 9 18 54 216 1296 current_numbers = 2 3 4 6 0 cum_prod = 2 6 24 144 0 current_numbers = 3 4 6 0 3 cum_prod = 3 12 72 0 0 current_numbers = 4 6 0 3 4 cum_prod = 4 24 0 0 0 current_numbers = 6 0 3 4 8 cum_prod = 6 0 0 0 0 current_numbers = 0 3 4 8 6 cum_prod = 0 0 0 0 0 current_numbers = 3 4 8 6 1 cum_prod = 3 12 96 576 576 current_numbers = 4 8 6 1 0 cum_prod = 4 32 192 192 0 current_numbers = 8 6 1 0 4 cum_prod = 8 48 48 0 0 current_numbers = 6 1 0 4 5 cum_prod = 6 6 0 0 0 current_numbers = 1 0 4 5 4 cum_prod = 1 0 0 0 0 current_numbers = 0 4 5 4 3 cum_prod = 0 0 0 0 0 current_numbers = 4 5 4 3 2 cum_prod = 4 20 80 240 480 current_numbers = 5 4 3 2 6 cum_prod = 5 20 60 120 720 current_numbers = 4 3 2 6 6 cum_prod = 4 12 24 144 864 current_numbers = 3 2 6 6 4 cum_prod = 3 6 36 216 864 current_numbers = 2 6 6 4 8 cum_prod = 2 12 72 288 2304 current_numbers = 6 6 4 8 2 cum_prod = 6 36 144 1152 2304 current_numbers = 6 4 8 2 1 cum_prod = 6 24 192 384 384 current_numbers = 4 8 2 1 3 cum_prod = 4 32 64 64 192 current_numbers = 8 2 1 3 3 cum_prod = 8 16 16 48 144 current_numbers = 2 1 3 3 9 cum_prod = 2 2 6 18 162 current_numbers = 1 3 3 9 3 cum_prod = 1 3 9 81 243 current_numbers = 3 3 9 3 6 cum_prod = 3 9 81 243 1458 current_numbers = 3 9 3 6 0 cum_prod = 3 27 81 486 0 current_numbers = 9 3 6 0 7 cum_prod = 9 27 162 0 0 current_numbers = 3 6 0 7 2 cum_prod = 3 18 0 0 0 current_numbers = 6 0 7 2 6 cum_prod = 6 0 0 0 0 current_numbers = 0 7 2 6 0 cum_prod = 0 0 0 0 0 current_numbers = 7 2 6 0 2 cum_prod = 7 14 84 0 0

5   Fail
%% s = '70066063155881748815209209628292540917153643678925903600113305305488'; i_correct = 44; assert(isequal(running_product(s),i_correct))

current_numbers = 7 0