It's a pity the test set does not include a case such that the largest running sum is not also the largest running product. Some solutions, including my solution of size 23, should fail because they take the sum, not the product.
I would suggest adding '9909911111' as a test case. That would weed out all people who took a shortcut by using a moving sum, instead of a moving product.
function i = running_product(s)
Moving sum of logarithm gives the moving product. Also, to reduce the code size, simply convolves log(+s) with any positive
constant, such as 32 (the ASCII code of space).
By taking log, the moving sum computed via convolution is indeed the moving product.
It's a very good idea!
Interesting idea. But the code can be simplified, as demonstrated in Solution 1373422, which cuts the size by 13.
A case of not enough tests in the Test Suite?
This solution also computes the running sum instead the product. The interesting thing to show here is that convn also works with char input
That's interesting. The documentation says it works only for double and single.
It's only because the test set is inadequate that this solution, which uses the running sum not the running product, works. My size-23 solution exploits the same loophole, but to see it done properly using convolution see my solution 19416, of size 25.
This should not be a solution, because it takes the sum, not the product. It's a pity the test set does not include a case such that the largest running sum is not also the largest running product.
This should use prod, not sum. As for my own solution 19425, the test cases fail to detect this error (at the time of writing).
surface of a spherical planet
Is my wife right? Now with even more wrong husband
Back to basics 14 - Keywords
Find perfect placement of non-rotating dominoes (easier)
select the primes of a vector
Alphabetize by last name
It dseon't mettar waht oedrr the lrettes in a wrod are.
Which doors are open?
Remove the polynomials that have positive real elements of their roots.
Find the treasures in MATLAB Central and discover how the community can help you!
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list:
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Contact your local office