how does this work some clarification
Mostrar comentarios más antiguos
can anyone explain how this solution work i tried to read documintations for this but did not really connect the dots
1 comentario
dareen
el 19 de Mzo. de 2024
Respuesta aceptada
Más respuestas (1)
John D'Errico
el 19 de Mzo. de 2024
1 voto
Honestly, this Cody answer is one of the reasons why I think Cody is seriously flawed. It encourages people to write obscene code, all for the purpose of gaming the scoring aogorithm. And then others see the code, and decide it is actually good code, because it has a low Cody score. (Puke, retch...)
How does it work? That part is trivial.
Can you tell me several ways to decide if a number is even or odd? What distinguishing characteristic does an even integer have, versus an odd one?
- An even integer is one that has a zero remainder when divided by 2.
- An even integer ends with a units digit in the set {0,2,4,6,8}.
Surely, I can think of some other rules that would work too. But the two rules above are the obvious ones.
Option 1 is easily tested. Sort of. Just test if rem(x,2) == 0. The problem is, you are passed not a number, but a string representation of that number. And test 1 in the test suite aims to prevent you from doing anything of the sort.
The solution the problem author probably wants you to find is one where the units digit of the number is extracted, then see if it is one of the valid even digits. That is all that was done here. Even better though, is to game the scoring by putting complex code into a string, then effectively using regex to do the dirty work.
1 comentario
dareen
el 19 de Mzo. de 2024
Categorías
Más información sobre Characters and Strings en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!