This is the first problem I create.
Thanks for your answer and your kind comments.
Regards
Adrian, welcome to Cody. That looks like an interesting problem. Unfortunately, there are only two test cases, and they contain the same answer. Hence, many of the answers supplied so far seem to game the system by just returning that one value. Please consider including more test cases with different answers to discourage hard-coded solutions that don't actually solve the problem. Note that even though the problem has been posted, you can still edit it.
I agree with goc3 (and M. Eicholtz).
One further point of detail is that you didn't actually need to set the existing two 'correct' answers to be identical. In reality the correct answers are 0.29990196 (approx.) and 0.2919 (exactly). While it is indeed admirable that you have employed a tolerance in your assertion command, with this type of problem there should be no difficulty for submissions to be accurate to at least 6 decimal places, so a tighter (stricter) tolerance is advisable here.
Test | Status | Code Input and Output |
---|---|---|
1 | Pass |
x = 1020;
h_correct = 0.3;
tolerance = 1e-4;
assert(abs(height(x)-h_correct)<tolerance)
|
2 | Pass |
x = 1000;
h_correct = 0.3;
tolerance = 1e-2;
assert(abs(height(x)-h_correct)<tolerance)
|
3892 Solvers
613 Solvers
216 Solvers
191 Solvers
121 Solvers
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!