Test case p(300)=9253082936723604 exceeds the maximum integer that can be represented exactly as a double precision number (namely, 2^53=9007199254740992); the fact that some solutions work for this case is just luck.
Changed to p(299), which is <2^53. Thanks for the heads up.
Interestingly, p(299) had some issues as well. Changed again to p(199), which seems to be working OK.
Test 2: function y = partitions(x) works!
Test 1: function y = partitions(n) fails
isn't it suppose to be partitions(x)?
But this is just function definition.
Either partitions(x) or partitions(n) should not matter in the function definition.
Strange. The problem you were having had something to do with the error checking suite that was above the solutions. Your solution passed the error checks, but failed to actually work. Now that I have removed the error checks, your solution with partitions(n) passes. I may have to muck around with this a bit later on.
The problem was with the following line in the error checking:
st = sprintf('function y = partitions(x)\n%%%s', st);
This automatically changed the first line of your script to use partitions(x) instead of partitions(n). That was done to prevent folks from using the "function ans=blahblahblah(x)" technique when that still worked, That was just a holdover that happened to trip you up. Now that that line (and the rest of the suite0 has been removed, partitions(n) should work just fine.
@James oops! I was so careless that I didn't notice that single-line error checking (I thought your check was intended to forbid the usage of functions such as eval, str2num, etc, and thus I completely ignored that when I was solving the problem). Now I realized this is not a strange behavior or bug of Cody. Thanks for your clarification.
Maximum running product for a string of numbers
1131 Solvers
Mirror Image matrix across anti-diagonal
111 Solvers
2595 Solvers
Split bread like the Pharaohs - Egyptian fractions and greedy algorithm
51 Solvers
61 Solvers
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!