Problem 42405. Divisible by 3
解决方案Stats
Problem Comments
-
7条评论
I don't understand your restrictions. OK for Java functions, but here you need mod/rem no ?
No, mod() or rem() isn't necessary because you can recursively apply the method, down to a single-digit number. The small number of single-digit numbers (i.e., 10, assuming absolute value) then makes checking against known divisible numbers trivial.
I understand the java restriction, but the rest seem a bit heavy handed. Also the large number of similar problems might encourage solvers to build a general "divisible by n" routine instead
I'm not trying to be authoritarian; just providing awareness to interesting mathematical trivia. There are some numbers, such as 7 and 11, for which a range of methods are possible. Without blocking a lot of those basic functions, very easy workarounds can be used, defeating the purpose of trying to optimize your score (akin to regexp, eval, etc. being banned due to defeating the scoring system).
Also, building a general "divisible by n" routine is a good idea and I had thought about posting that at the end of the group of problems. I just think that it's too big for a standalone problem. There are many problems on Cody that are extremely simple and require no thought (like the recent string of beginner problems). There are also quite a few that require significant time, thought, and/or programming to solve, but they are all worth the same number of points. I prefer to break more difficult problems into simpler modules (just like is done in programming) to provide an encouraging approach, especially to those not already expert in Matlab. There are similarities between many of the problems in this set, but some numbers require quite different methods, such as 7 and 11.
Solved problems before reading comments and must agree with Alfonso. "divisible by N" approach worked nicely through all of them.
Thanks for the comment. I'll be adding a few more problems to this set in the near future to round out and finish up the "divisible by N" approach.
解决方案Comments
-
1 Comment
为什么不可见测试套件?是我(Firefox显示问题)还是应该这样?
-
2 Comments
我唯一的失败吗test 12?
I get tf=0 when i run this in Matlab...
That test case has the longest string input, by far. Your solution is coded to only sum digits twice. After those two steps, the resulting sum in this specific case is still greater than 9, and, therefore, fails your test of equal to a single-digit multiple of three (3, 6, or 9).
-
1 Comment
First time I see ismembertol.Nice !
-
1 Comment
Is this machine dependent?
-
1 Comment
I love the simplicity of this one!
问题最近的求解器347
建议的问题
1834 Solvers
What is the distance from point P(x,y) to the line Ax + By + C = 0?
317求解器
Return the first and last characters of a character array
6034求解器
506求解器
Check that number is whole number
2288 Solvers
来自作者的更多139
Problem Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
开始狩猎!