This solution is outdated. To rescore this solution, sign in.
-
4 Comments
Hi,
Could you comment how using str2num and anonymous functions decreases the score from 46 to 13? Is it a glinch in the notation system?
Regards
Hi, Florent.
The scoring in Cody is based on the number of nodes in the parse tree, and strings only require one node.
You can have a look for yourself by typing:
'>> mtree('back_and_forth.m','-file').show'.
Try to do it for the same code, without str2num, and you'll see that even small things like parenthesis or plus signs require their own node in the tree.
In terms of performance, the two versions are not so different. The problem here is that every solution, that use str2num in this way, will have the same Cody score, regardless of how elegant or efficient the anonymous function is.
I really like how you've split the matrix into two. That's a clever insight! And I am really interested in knowing WHY str2num requires only one node.
Suggested Problems
-
Switch matrix to a column vector
360 Solvers
-
492 Solvers
-
388 Solvers
-
985 Solvers
-
978 Solvers
More from this Author96
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!