I don't understand the failed test message

3 vues (au cours des 30 derniers jours)
Nourhan
Nourhan le 21 Août 2023
Commenté : Dyuman Joshi le 21 Août 2023
Hello,
I was solving some cody problem called perfect squares that asks for a given vector of numbers, return true if one of the numbers is a square of one of the numbers. Otherwise return false.
Example:
input a = [2 3 4]
output b is true
my code
function b = isItSquare(a)
y = []
for i = 1:length(a)
j = 1:length(a)
if a(i) == a(j)^2
y = horzcat(y,1)
else
y = horzcat(y,0)
end
end
end
if any(y(:)) ==1
b = true
else
b = false
end
end
I got 7 out of 8 tests correct, the first test is incorrect
I don't even understand what does this mean?
  1 commentaire
Torsten
Torsten le 21 Août 2023
Maybe one of the challenges was not to use "else" in your code ? But you used it ...

Connectez-vous pour commenter.

Réponse acceptée

Dyuman Joshi
Dyuman Joshi le 21 Août 2023
Hi @Nourhan, Cody moderator here
As @Torsten mentions, that particular test case checks for some keywords, to see if they are present or not in the submitted code.
The first 2 keywords are generally used to hack through the cody system and get either low scoring solutions or solve a problem without actually solving it. The last 2 keywords are often used to submit a hard-coded solution.
Thus this particular combination of keywords are usually banned.
However, I have removed the last 2 keywords from the test suite and added some cases with random values so that it is not possible to submit a hard-coded solution.
I have rescored your solution and it is now accepted.
Additionally, I would suggest you to go through your code and see where you can change it to make it more efficient.
You can also think of other approaches for this problem, particularly in the direction of a vectorized solution. You can also check other submitted solutions for help/hint.
  2 commentaires
Nourhan
Nourhan le 21 Août 2023
Thank you so much and I will try to improve my solution
Dyuman Joshi
Dyuman Joshi le 21 Août 2023
Glad to have helped!
You can also comment on a solution or a problem on Cody if you need help, and I'll respond accordingly.

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Communications Toolbox dans Help Center et File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by