Problem 713. Find the maximum number of decimal places in a set of numbers
Solution Stats
Problem Comments
-
15 Comments
hại não
good for improve skill
@Ayesha Alfili HCT2021: your comment was deleted, as it revealed a large part of a potential solution. If you need help with an attempted solution, comment on that solution without copying it into a comment.
I feel some uncomfortableness to solve with a not mathematical method, like text processing. But it may smarter than take care of floating point, round error, etc.
hi my code works for tests 1 3 4 but not for test 2, can anyone help me?
here is my code:
function y = find_max_sigdec(x)
how_much_dec=[0]*[length(x)];
for i=1:length(x);
count=0;
while x(i)~=round(x(i))
x(i)=x(i)*10;
count=count+1;
end
how_much_dec(i)=count
end
y=max(how_much_dec)
end
struggled for a bit with "format long" adding a value at 1e15.
definitely a tough problem!
Easy problem, vexing test suite. Be sure to clear the workspace (especially x) between tests!
Good problem. But don't waste your time trying to achieve size 10. It took me a couple of hours to figure out that it's just a trick using a built-in function to evaluate the program embedded within a string. This shouldn't be acceptable. The smallest solution size is probably in the 20s.
Easy if solved using strings,
Hard if solved using algorithms.
The assert against the use of 'if' is atrocious. No point in being there.
I hate the way computers handle floating point numbers. I had a solution in 5 minutes that took me an hour to troubleshoot because, according to Matlab, mod(x,1) = 1.
@Brandon I was a little concerned by your comment, but it appears that in MATLAB, mod(x, 1) is 0 for all integer x. I'm curious as to where you've observing different behavior?
I don't understand how to solve using strings..
hi
fun
Solution Comments
Show commentsProblem Recent Solvers2801
Suggested Problems
-
2121 Solvers
-
Is my wife right? Now with even more wrong husband
1322 Solvers
-
5457 Solvers
-
288 Solvers
-
Find out sum and carry of Binary adder
1463 Solvers
Problem Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!