Cody

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

Solution 2122716

Submitted on 9 Feb 2020 by heart
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))

d = 0 0.6931 1.0986 1.3863 1.6094 0.6931 1.0986 1.3863 1.6094 1.3863 1.0986 1.3863 1.6094 1.3863 1.0986 1.3863 1.6094 1.3863 1.0986 0.6931 1.6094 1.3863 1.0986 0.6931 0 d = 4.7875 6.1738 6.5793 6.1738 4.7875 i = 3

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

d = 1.6094 2.0794 0.6931 -Inf 2.1972 2.0794 0.6931 -Inf 2.1972 1.9459 0.6931 -Inf 2.1972 1.9459 1.3863 -Inf 2.1972 1.9459 1.3863 2.1972 2.1972 1.9459 1.3863 2.1972 1.3863 1.9459 1.3863 2.1972 1.3863 1.3863 1.3863 2.1972 1.3863 1.3863 1.6094 2.1972 1.3863 1.3863 1.6094 2.1972 1.3863 1.3863 1.6094 2.1972 0.6931 1.3863 1.6094 2.1972 0.6931 1.0986 1.6094 2.1972 0.6931 1.0986 -Inf 2.1972 0.6931 1.0986 -Inf 1.9459 0.6931 1.0986 -Inf 1.9459 2.0794 1.0986 -Inf 1.9459 2.0794 0 -Inf 1.9459 2.0794 0 1.7918 1.9459 2.0794 0 1.7918 1.3863 2.0794 0 1.7918 1.3863 -Inf 0 1.7918 1.3863 -Inf 1.7918 1.7918 1.3863 -Inf 1.7918 0.6931 1.3863 -Inf 1.7918 0.6931 2.0794 -Inf 1.7918 0.6931 2.0794 1.7918 1.7918 0.6931 2.0794 1.7918 0.6931 0.6931 2.0794 1.7918 0.6931 -Inf 2.0794 1.7918 0.6931 -Inf 2.0794 1.7918 0.6931 -Inf 2.0794 2.1972 0.6931 -Inf 2.0794 2.1972 2.1972 -Inf 2.0794 2.1972 2.1972 2.0794 2.0794 2.1972 2.1972 2.0794 1.7918 2.1972 2.1972 2.0794 1.7918 0.6931 2.1972 2.0794 1.7918 0.6931 2.0794 2.0794 1.7918 0.6931 2.0794 -Inf 1.7918 0.6931 2.0794 -Inf 1.0986 0.6931 2.0794 -Inf 1.0986 1.3863 2.0794 -Inf 1.0986 1.3863 2.0794 -Inf 1.0986 1.3863 2.0794 0.6931 1.0986 1.3863 2.0794 0.6931 1.6094 1.3863 2.0794 0.6931 1.6094 1.0986 2.0794 0.6931 1.6094 1.0986 1.3863 0.6931 1.6094 1.0986 1.3863 0.6931 1.6094 1.0986 1.3863 0.6931 0 1.0986 1.3863 0.6931 0 0 1.3863 0.6931 0 0 1.9459 0.6931 0 0 1.9459 -Inf 0 0 1.9459 -Inf 1.7918 0 1.9459 -Inf 1.7918 1.9459 d = -Inf -Inf -Inf -Inf 9.1129 8.3020 7.9655 8.7765 7.2724 6.9847 -Inf -Inf -Inf -Inf -Inf 7.2034 -Inf -Inf -Inf -Inf -Inf 7.0493 -Inf -Inf -Inf -Inf -Inf 10.3451 8.9588 8.8410 -Inf -Inf -Inf -Inf -Inf 6.8669 6.8669 6.8669 5.4806 4.7875 3.1781 4.0254 -Inf -Inf -Inf i = 28

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

d = 0 1.3863 0 1.6094 2.1972 1.3863 0 1.6094 2.1972 0.6931 0 1.6094 2.1972 0.6931 1.7918 1.6094 2.1972 0.6931 1.7918 1.6094 2.1972 0.6931 1.7918 1.6094 1.0986 0.6931 1.7918 1.6094 1.0986 1.6094 1.7918 1.6094 1.0986 1.6094 2.0794 1.6094 1.0986 1.6094 2.0794 2.1972 1.0986 1.6094 2.0794 2.1972 1.9459 1.6094 2.0794 2.1972 1.9459 2.1972 2.0794 2.1972 1.9459 2.1972 1.0986 2.1972 1.9459 2.1972 1.0986 0.6931 1.9459 2.1972 1.0986 0.6931 1.0986 2.1972 1.0986 0.6931 1.0986 2.0794 1.0986 0.6931 1.0986 2.0794 1.3863 0.6931 1.0986 2.0794 1.3863 1.7918 1.0986 2.0794 1.3863 1.7918 0.6931 2.0794 1.3863 1.7918 0.6931 1.7918 1.3863 1.7918 0.6931 1.7918 1.3863 1.7918 0.6931 1.7918 1.3863 1.0986 0.6931 1.7918 1.3863 1.0986 1.0986 1.7918 1.3863 1.0986 1.0986 2.0794 1.3863 1.0986 1.0986 2.0794 1.0986 1.0986 1.0986 2.0794 1.0986 0.6931 1.0986 2.0794 1.0986 0.6931 1.9459 2.0794 1.0986 0.6931 1.9459 2.1972 1.0986 0.6931 1.9459 2.1972 1.6094 0.6931 1.9459 2.1972 1.6094 -Inf 1.9459 2.1972 1.6094 -Inf 0.6931 2.1972 1.6094 -Inf 0.6931 2.0794 1.6094 -Inf 0.6931 2.0794 2.0794 -Inf 0.6931 2.0794 2.0794 1.3863 0.6931 2.0794 2.0794 1.3863 0 2.0794 2.0794 1.3863 0 2.1972 2.0794 1.3863 0 2.1972 1.9459 1.3863 0 2.1972 1.9459 0 0 2.1972 1.9459 0 1.7918 2.1972 1.9459 0 1.7918 2.1972 1.9459 0 1.7918 2.1972 1.0986 0 1.7918 2.1972 1.0986 2.1972 1.7918 2.1972 1.0986 2.1972 2.1972 2.1972 1.0986 2.1972 2.1972 1.0986 1.0986 2.1972 2.1972 1.0986 2.1972 2.1972 2.1972 1.0986 2.1972 2.1972 2.1972 1.0986 2.1972 2.1972 2.1972 1.0986 2.1972 2.1972 2.1972 2.1972 2.1972 2.1972 2.1972 2.1972 2.1972 d = 5.1930 5.8861 6.2916 7.9010 7.3902 6.8024 8.1887 8.5942 8.9306 10.0292 9.5184 8.1321 7.0335 7.1670 6.3561 7.0493 7.0493 7.7424 7.0493 6.7616 6.0684 7.4547 6.7616 6.0684 6.9157 8.0143 7.5443 -Inf -Inf -Inf -Inf -Inf 6.2383 7.7424 7.6089 5.5294 5.9349 8.1321 7.0335 7.2848 9.4820 8.7889 8.7889 9.8875 9.8875 9.8875 10.9861 i = 47

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

d = 1.9459 2.0794 1.0986 0 1.7918 2.0794 1.0986 0 1.7918 1.6094 1.0986 0 1.7918 1.6094 0.6931 0 1.7918 1.6094 0.6931 1.9459 1.7918 1.6094 0.6931 1.9459 0 1.6094 0.6931 1.9459 0 0.6931 0.6931 1.9459 0 0.6931 -Inf 1.9459 0 0.6931 -Inf 0 0 0.6931 -Inf 0 2.1972 0.6931 -Inf 0 2.1972 -Inf -Inf 0 2.1972 -Inf 2.1972 0 2.1972 -Inf 2.1972 0 2.1972 -Inf 2.1972 0 1.3863 -Inf 2.1972 0 1.3863 1.6094 2.1972 0 1.3863 1.6094 1.7918 0 1.3863 1.6094 1.7918 1.3863 1.3863 1.6094 1.7918 1.3863 2.0794 1.6094 1.7918 1.3863 2.0794 1.6094 1.7918 1.3863 2.0794 1.6094 1.7918 1.3863 2.0794 1.6094 1.7918 1.7918 2.0794 1.6094 1.7918 1.7918 2.1972 1.6094 1.7918 1.7918 2.1972 0.6931 1.7918 1.7918 2.1972 0.6931 1.0986 1.7918 2.1972 0.6931 1.0986 1.3863 2.1972 0.6931 1.0986 1.3863 1.7918 0.6931 1.0986 1.3863 1.7918 -Inf 1.0986 1.3863 1.7918 -Inf 1.0986 1.3863 1.7918 -Inf 1.0986 1.3863 1.7918 -Inf 1.0986 1.3863 2.0794 -Inf 1.0986 1.3863 2.0794 1.7918 1.0986 1.3863 2.0794 1.7918 0 1.3863 2.0794 1.7918 0 -Inf 2.0794 1.7918 0 -Inf 1.3863 1.7918 0 -Inf 1.3863 1.6094 0 -Inf 1.3863 1.6094 1.3863 -Inf 1.3863 1.6094 1.3863 1.0986 1.3863 1.6094 1.3863 1.0986 0.6931 1.6094 1.3863 1.0986 0.6931 1.7918 1.3863 1.0986 0.6931 1.7918 1.7918 1.0986 0.6931 1.7918 1.7918 1.3863 0.6931 1.7918 1.7918 1.3863 2.0794 1.7918 1.7918 1.3863 2.0794 0.6931 1.7918 1.3863 2.0794 0.6931 0 1.3863 2.0794 0.6931 0 1.0986 2.0794 0.6931 0 1.0986 1.0986 0.6931 0 1.0986 1.0986 2.1972 0 1.0986 1.0986 2.1972 1.0986 1.0986 1.0986 2.1972 1.0986 1.7918 1.0986 2.1972 1.0986 1.7918 -Inf 2.1972 1.0986 1.7918 -Inf 1.9459 1.0986 1.7918 -Inf 1.9459 0.6931 1.7918 -Inf 1.9459 0.6931 1.7918 -Inf 1.9459 0.6931 1.7918 -Inf 1.9459 0.6931 1.7918 -Inf 0.6931 d = 6.9157 6.5793 5.1930 6.0403 6.0403 4.9416 -Inf -Inf -Inf -Inf -Inf -Inf -Inf -Inf 6.9847 6.1738 8.2532 8.4764 8.6587 8.6587 9.4696 8.0833 7.5725 7.1670 7.1670 -Inf -Inf -Inf -Inf -Inf 6.3561 -Inf -Inf -Inf -Inf -Inf 6.1738 6.5793 6.7616 6.7616 7.7424 7.7424 5.9506 5.2575 4.9698 5.0876 5.4931 7.2848 -Inf -Inf -Inf -Inf -Inf -Inf i = 21

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

d = 1.9459 -Inf -Inf 1.7918 1.7918 -Inf -Inf 1.7918 1.7918 -Inf -Inf 1.7918 1.7918 -Inf 1.7918 1.7918 1.7918 -Inf 1.7918 1.0986 1.7918 -Inf 1.7918 1.0986 0 -Inf 1.7918 1.0986 0 1.6094 1.7918 1.0986 0 1.6094 1.6094 1.0986 0 1.6094 1.6094 2.0794 0 1.6094 1.6094 2.0794 2.0794 1.6094 1.6094 2.0794 2.0794 0 1.6094 2.0794 2.0794 0 1.9459 2.0794 2.0794 0 1.9459 1.3863 2.0794 0 1.9459 1.3863 2.0794 0 1.9459 1.3863 2.0794 2.0794 1.9459 1.3863 2.0794 2.0794 0 1.3863 2.0794 2.0794 0 1.6094 2.0794 2.0794 0 1.6094 0.6931 2.0794 0 1.6094 0.6931 -Inf 0 1.6094 0.6931 -Inf 2.1972 1.6094 0.6931 -Inf 2.1972 0.6931 0.6931 -Inf 2.1972 0.6931 -Inf -Inf 2.1972 0.6931 -Inf 2.1972 2.1972 0.6931 -Inf 2.1972 1.7918 0.6931 -Inf 2.1972 1.7918 0.6931 -Inf 2.1972 1.7918 0.6931 2.0794 2.1972 1.7918 0.6931 2.0794 0.6931 1.7918 0.6931 2.0794 0.6931 2.1972 0.6931 2.0794 0.6931 2.1972 0.6931 2.0794 0.6931 2.1972 0.6931 1.6094 0.6931 2.1972 0.6931 1.6094 1.3863 2.1972 0.6931 1.6094 1.3863 -Inf 0.6931 1.6094 1.3863 -Inf 2.1972 1.6094 1.3863 -Inf 2.1972 0 1.3863 -Inf 2.1972 0 1.9459 -Inf 2.1972 0 1.9459 0 2.1972 0 1.9459 0 1.6094 0 1.9459 0 1.6094 1.0986 1.9459 0 1.6094 1.0986 1.7918 0 1.6094 1.0986 1.7918 1.3863 1.6094 1.0986 1.7918 1.3863 1.0986 1.0986 1.7918 1.3863 1.0986 1.7918 1.7918 1.3863 1.0986 1.7918 1.9459 1.3863 1.0986 1.7918 1.9459 2.0794 1.0986 1.7918 1.9459 2.0794 2.1972 1.7918 1.9459 2.0794 2.1972 0.6931 1.9459 2.0794 2.1972 0.6931 1.6094 2.0794 2.1972 0.6931 1.6094 2.1972 2.1972 0.6931 1.6094 2.1972 -Inf 0.6931 1.6094 2.1972 -Inf 1.0986 1.6094 2.1972 -Inf 1.0986 1.7918 2.1972 -Inf 1.0986 1.7918 -Inf -Inf 1.0986 1.7918 -Inf -Inf 1.0986 1.7918 -Inf -Inf 0 1.7918 -Inf -Inf 0 0 -Inf -Inf 0 0 1.0986 -Inf 0 0 1.0986 1.0986 0 0 1.0986 1.0986 -Inf 0 1.0986 1.0986 -Inf 1.6094 1.0986 1.0986 -Inf 1.6094 1.0986 1.0986 -Inf 1.6094 1.0986 -Inf -Inf 1.6094 1.0986 -Inf 1.6094 1.6094 1.0986 -Inf 1.6094 1.3863 1.0986 -Inf 1.6094 1.3863 2.0794 -Inf 1.6094 1.3863 2.0794 2.0794 d = -Inf -Inf -Inf -Inf -Inf -Inf 6.1092 6.3969 7.3778 7.3778 7.7142 7.4911 7.4911 7.4911 7.4911 7.1546 6.4615 -Inf -Inf -Inf -Inf -Inf -Inf -Inf -Inf 7.4547 7.4547 6.3561 7.2724 6.5793 -Inf -Inf -Inf -Inf -Inf 5.7526 4.6540 6.4457 5.8861 6.9847 7.1670 8.0143 8.3020 9.1129 8.7075 8.5252 8.7765 -Inf -Inf -Inf -Inf -Inf -Inf -Inf -Inf -Inf -Inf -Inf -Inf -Inf -Inf -Inf -Inf -Inf i = 44

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

d = 0 0 0 0 0 d = 0 i = 1