Hi everyone
I could use a bit of help on this solution, as i am just a freshman. By reading it now line 4 mind sound strange, but without it, it didn't work. I always had one penny less than expected. I thought, that this could be a numerical problem using mod() and fix() in the way, that the mod function decreases the value a litte bit and than fix doesn't work right. I am not quiet sure and could need some help by an experienced matlab user. Thanks in advance and a nice day :)
Lukas
In test case 2, 135.01 is represented internally as 135.009999999999991, so the fractional part is slightly less than 0.01, which leads to the problem. You could try rounding the input (and the change vector) to an integer number of pennies so all the calculations would use integers.
Test | Status | Code Input and Output |
---|---|---|
1 | Pass |
%%
a = [257.68];
b = [2 1 0 0 1 1 0 1 0 1 1 3];
out = makingChange(a);
assert(isequal(out(:), b(:)))
a =
257.6890
|
2 | Pass |
%%
a = [135.01];
b = [1 0 1 1 1 0 0 0 0 0 0 1];
out = makingChange(a);
assert(isequal(out(:), b(:)))
a =
135.0190
|
3 | Pass |
%%
a = [10035.99];
b = [100 0 1 1 1 0 0 1 1 2 0 4];
out = makingChange(a);
assert(isequal(out(:), b(:)))
a =
1.0036e+04
|
900 Solvers
Project Euler: Problem 5, Smallest multiple
397 Solvers
First non-zero element in each column
593 Solvers
Determine Whether an array is empty
646 Solvers
2455 Solvers
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!