how does this work some clarification
古いコメントを表示
can anyone explain how this solution work i tried to read documintations for this but did not really connect the dots
採用された回答
その他の回答 (1 件)
John D'Errico
2024 年 3 月 19 日
1 投票
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.
カテゴリ
ヘルプ センター および File Exchange で Characters and Strings についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!