Problem 53725. Easy Sequences 56: Counting "Ugly" Numbers
Solution Stats
Problem Comments
-
8 Comments
Hi Michael,
I commented out test 7, for other players to check and I added test 8, which gives the same values even if we switch the places of log(2) and log(5). I've tested it with your first solution. Please try again and please like and rate the problem. You my also try my other problems::
https://www.mathworks.com/matlabcentral/cody/players/13897958/created.
Thanks,.
Hmm... the test suite has the wrong answer, but it appears to be MATLAB's fault. It appears that in test case 8, when called with 9 and 100, the "successful" solutions miss 9^100 as an ugly number, which it clearly is. It appears to be an issue with the colon operator.
Here's an easy way to isolate the error:
>> 199:100*log(9)/log(3)
ans =
199.0000 200.0000
>> ans(end)-200
ans =
2.8422e-14
>>
Just the fact that the first answer is showing floating point numbers is a clue, but the second one should clearly return 0, or -1 if the roundoff error between log(9) and log(3) had gone the other way.
I posted a bug report and was told it was a feature. I did a bit of push back, and they agreed that the documented behavior and the actual differ, and to take on a fix for a future update or release. Not clear whether they'll fix the behavior or change the documentation.
Solution Comments
Show commentsProblem Recent Solvers6
Suggested Problems
-
2332 Solvers
-
Renaming a field in a structure array
1549 Solvers
-
1648 Solvers
-
Back to basics 22 - Rotate a matrix
910 Solvers
-
Vectorize the digits of an Integer
325 Solvers
More from this Author116
Problem Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!