Problem 9. Who Has the Most Change?
You have a matrix for which each row is a person and the columns represent the number of quarters, nickels, dimes, and pennies that person has (in that order). What is the row index of the person with the most money?
Note for those unfamiliar with American coins: quarter = $0.25, dime = $0.10, nickel = $0.05, penny = $0.01.
Example:
Input a = [1 0 0 0; 0 1 0 0] Output b = 1
since the first person will have $0.25 and the second person will have only $0.05.
Solution Stats
Problem Comments

62 Comments
Test #5 seems false:
a = [ 0 1 2 1; 0 2 1 1];
b = 1; % (> should be 2)
agreed :(
still broken...
No wonder why the solution map is 99% red...
Fixed. The solutions are being rescored now.
Still broken I think. The question emphasises that the order is nickels before dimes.
... and the example also gives the value of [0 1 0 0] as 0.05, so nickels come second, not third. My solution with dimes second is still showing as correct.
Folks this is still broken (perhaps the wording above is wrong?) [0 1 2 1; 0 2 1 1] still not tested correctly.
The columns should be Quarters, Dimes, Nickels, Pennies. That works as of right now.
I've fixed test #5. Sorry about that!
Test #5 still says a = [ 0 1 2 1; 0 2 1 1]; c = 1. (maybe we have to wait until the server cache is flushed)
Test #5 is still broken.
last test is flawed
I have examined the test suite carefully, and it is correct. This problem is about close reading as much as anything. Please read the first sentence of the problem very carefully.
Yup...it's a petty statement. For those of you who skim the first sentence and then LOOK at the order of the coins below, here's the trick. The specified order is not quarters, dimes, nickels, pennies. So this is not a problem about using MATLAB to solve a problem...it's about reading the problem statement closely. I made the same mistake several times, largely because I saw the coin order where the coin values are listed and went with what I would consider the "natural" order were I actually programming such a calculation. Setting up the vector /this/ way would be as confusing in real life as it is here, and is contraindicated for good programming standards.
Next time hopefully I'll have a computer read for me...
I concur with Ninetrees.
I agree with the last three comments, and I think it is especially 'unfair' for nonamericans. If you don't automatically know te values, you will (of course) directly look at the nice 'conversion scheme' that is given, think 'thank you for that' and go completely wrong.
Unless this is of course also teaching about 'commenting in an understandable way.
orders of changes are different in question and note!
So everybody should note that the nickel and dime order is flipped..
This switch made this problem too frustrating!
but i liked it!
i have never used '$',so i got a little frustrated first.
it's not so complicated when you multiply a and vertical matrix containing values
dime=$0.05, nickel=$0.10 :)) unbelieveable but I liked it!
tricky, but nice!
interesting problem!
The problem description is a bit confusing.
... the columns represent the number of quarters, nickels, dimes, and pennies
but then in the note they are listed in a different order
quarter = $0.25, dime = $0.10, nickel = $0.05, penny = $0.01
Not sure if this was on purpose, but it tricked me.
Really silly that the order is supposed to be quarters(.25), nickels(.05), dimes(.1), pennies(.01) when one would expect it to be in descending order. I'm sure a lot of the incorrect solutions had good code but were tricked up by the question.
Case 5; a = [ 0 1 2 1; 0 2 1 1]; c = 1; a(1, :) = 0*.25+1*.10+ 2*0.05 + 1*0.01 = $ 0.21 a(2, :) = 0*.25+2*.10+ 1*0.05 + 1*0.01 = $ 0.26 so, output should be 2. and, for Case 6 a(1, :) = $ .10; a(2, :) = $ .05; so output should be 1
i like the little trick
Nice
Sneaky...
Can someone tell me whats wrong with test no. 5 and 6. ?
Sneaky indeed
I think the problem poster messed up, and didn't want to change his solution... lol
Haha this one made me laugh when the assertion test told me to go back and read it again.
The text 5 is wrong!
yup, that's the line you need to read carefully!
"number of quarters, nickels, dimes, and pennies that person has (in that order)"
Solvable if we notice(^^;
Check the order! The question requires 'quarters, NICKELS, DIMES, and pennies' and NOT 'quarters, DIMES, NICKELS and pennies'
This was a really cool problem. After some thinking and trial and error a solution was not too hard to find. Cool problem!
Check the order in the description: 'quarters, NICKELS, DIMES, and pennies' and NOT 'quarters, DIMES, NICKELS and pennies'
one way to do as i figured c=[0.25 0.05 0.1 0.01];
b = find(sum(a.*c,2) == max(sum(a.*c,2)));
Funny ;)
It's a trap!
Very sneaky...
What does the 'c' stand for in the proposed tests 5 to end?
Is it not possible to attach my code in the solution?
Thanks.
could anyone take a look at my solution and hint how i could simplify??
I have provided so much incorrect solutions...
The following test case run by the test suite does not make any sense for my answer:
%%
a = [ 0 1 2 1; 0 2 1 1];
c = 1;
assert(isequal(most_change(a),c))
%%
% There is a lot of confusion about this problem. Watch this.
a = [0 1 0 0; 0 0 1 0];
c = 2;
assert(isequal(most_change(a),c))
% Now go back and read the problem description carefully.
please check.
Read the description of the problem carefully. The author specifically says: quarters, NICKELS, DIMES and pennies.
If you still have problems, that's the part where you should be careful at.
Reading the description again and again gives you a lot of clarity. Tricky one :p
It would be great, if there would be a DOWNvote button. Why should one provide an unordered list?
LOL, this a troll of a problem  as others say, the input array isn't the normal order of the coins  they even add the values of each of these coins in the correct order later in the description just to mess with you XD
I'm also amused by how many people are passionately defending the problemcreator  I can't decide if it's a brilliant troll or just plain old annoying, but being a teacher's pet is the incorrect answer to life (even if it gets you far).
Although the problem is easy enough but the instructions given in the way is ridiculous
BE CAREFUL WITH THE NUMBERS TWIST AT THE START!
The currency is not sorted in descending or ascending order
Interesting exercise
A play on words.........
Can we ban stupid problems like this? Like, how do I report a problem to have it moderated out of existence?
I have tagged this problem as stupid. I encourage others to do the same. This is a place to learn, not to ask trick questions.
@Brandon, what makes you think one can not learn from trick questions?
If nothing else one can learn to read a task's description carefully before starting to write code, which I would argue is fairly important when doing any kind of programming.
Solution Comments
Show commentsProblem Recent Solvers8625
Suggested Problems

Sum all integers from 1 to 2^n
14096 Solvers

Back to basics 6  Column Vector
1042 Solvers

465 Solvers

Area of an equilateral triangle
5674 Solvers

628 Solvers
More from this Author96
Problem Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!