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.
Find state names that start with the letter N
Program an exclusive OR operation with logical operators
Back to basics 10 - Max Float
Matrix indexing with two vectors of indices
Replace multiples of 5 with NaN
Decimation - Optimized for speed
Converting numbers back from extended form
Fun with a compass
Should Mr McNugget even get out of bed today?
Return elements unique to either input
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