This scoring method leads to horrible coding. This is teaching horrible coding. No actual code should ever use ans.
Second thought: I believe this algorithm is not bullet-proof. what if a = [4,6,12,18]?
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.
This iterationg is good indeed.
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...
Find the sum of all the numbers of the input vector
Project Euler: Problem 1, Multiples of 3 and 5
Number of Circles in a Number
Create a Multiplication table matrix...
Check that number is whole number
Select every other element of a vector
Find relatively common elements in matrix rows
Add two numbers
Determine if input is odd
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