Given the vector a, find the longest run of consecutive numbers that can be evenly divided by the same number d where d > 1.
Example:
Input a = [5 4 2 8 3 7 14] Output len is 3, d is 2
The last two numbers, 7 and 14, are divisible by 7, but the run of numbers [4 2 8] are all divisible by 2. So the longest run is 3. You can assume that d is unique.
I am passing all test suit case in MATLAB 207b but I am getting this message:
While evaluating the solution, the server encountered an error caused by long running MATLAB code. Edit the code if needed and then submit.
Based on Gangyi's solution (Solution 57169). (And with thanks to Alfonso for directing my attention towards it. :-)
Flawed solution; it fails when (for example) a = [2 10 20 30] .
This solution just confirms my belief that the code size measure needs to count code executed within a regexp.
This Solution is a little difficult to obtain,but seems like an approach.
good trick
Yes, the size matters for this scoring, but using m(a)=0 makes for a grossly large vector. I'm not a big fan of this type of solution, which seems to make up the shortest solutions.
If you do not care about Cody-'size' solution 66088 implements the same algorithm more efficiently (using sparse vectors instead of a 'grossly large' matrix)...
my personal favourite nevertheless is Gangyi's 57169 solution, which seems to run typically twice as fast a my version...
Test if a Number is a Palindrome without using any String Operations
213 Solvers
random picture with random colours
160 Solvers
Project Euler: Problem 3, Largest prime factor
281 Solvers
303 Solvers
297 Solvers