Cody

Problem 54. Maximum running product for a string of numbers

Solution 1595171

Submitted on 29 Jul 2018 by Hans Hudyncia
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))

s = 1 2 3 4 5 4 3 2 1 ans = 6 24 120 480 720 480 120 24 6 index = 3 i = 3

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

s = Columns 1 through 30 5 8 2 0 9 7 4 9 4 4 5 9 2 3 0 7 8 1 6 4 0 6 2 8 6 2 0 8 9 9 Columns 31 through 49 8 6 2 8 0 3 4 8 2 5 3 4 2 1 1 7 0 6 7 ans = Columns 1 through 15 80 0 0 0 0 0 9072 4032 2880 6480 1440 1080 0 0 0 Columns 16 through 30 0 0 1344 0 0 0 0 0 1152 0 0 0 0 0 31104 Columns 31 through 45 7776 6912 0 0 0 0 0 960 960 960 240 120 24 56 0 Columns 46 through 49 0 0 0 0 index = 28 i = 28

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

s = Columns 1 through 30 1 4 1 5 9 2 6 5 3 5 8 9 7 9 3 2 3 8 4 6 2 6 4 3 3 8 3 2 7 9 Columns 31 through 51 5 0 2 8 8 4 1 9 7 1 6 9 3 9 9 3 9 9 9 9 9 ans = Columns 1 through 15 4 20 180 360 540 2700 1620 900 3600 5400 7560 22680 13608 3402 1134 Columns 16 through 30 1296 576 1152 1152 2304 1152 864 432 1728 864 432 1008 3024 1890 0 Columns 31 through 45 0 0 0 0 512 2304 2016 252 378 3402 1134 1458 13122 6561 6561 Columns 46 through 51 19683 19683 19683 59049 6561 729 index = 47 i = 47

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

s = Columns 1 through 30 7 8 3 1 6 5 2 7 1 2 0 1 9 0 9 1 4 5 6 4 8 5 6 6 9 2 3 4 6 0 Columns 31 through 58 3 4 8 6 1 0 4 5 4 3 2 6 6 4 8 2 1 3 3 9 3 6 0 7 2 6 0 2 ans = Columns 1 through 15 168 168 1008 720 180 420 420 140 0 0 0 0 0 0 0 Columns 16 through 30 0 1080 480 3840 4800 5760 5760 12960 3240 1944 1296 1296 0 0 0 Columns 31 through 45 0 0 576 0 0 0 0 0 480 720 864 864 2304 2304 384 Columns 46 through 58 192 144 162 243 1458 0 0 0 0 0 0 0 0 index = 21 i = 21

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

s = Columns 1 through 30 7 0 0 6 6 0 6 3 1 5 5 8 8 1 7 4 8 8 1 5 2 0 9 2 0 9 6 2 8 2 Columns 31 through 60 9 2 5 4 0 9 1 7 1 5 3 6 4 3 6 7 8 9 2 5 9 0 3 6 0 0 1 1 3 3 Columns 61 through 68 0 5 3 0 5 4 8 8 ans = Columns 1 through 15 0 0 0 0 0 0 0 0 450 600 1600 1600 2240 1792 1792 Columns 16 through 30 1792 1792 1280 640 0 0 0 0 0 0 0 0 1728 1728 576 Columns 31 through 45 1440 720 0 0 0 0 0 315 105 630 360 1080 1296 3024 4032 Columns 46 through 60 9072 6048 5040 6480 0 0 0 0 0 0 0 0 0 0 0 Columns 61 through 68 0 0 0 0 0 0 1280 256 index = 44 i = 44

6   Pass
s = '11111'; i_correct = 1; assert(isequal(running_product(s),i_correct))

s = 1 1 1 1 1 ans = 1 1 1 1 1 index = 1 i = 1