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 non-americans. 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!
Please, delete this problem.
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 problem-creator - 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.........
using martrix multiplitation make this problem easier.
You need to consider the order given in the problem description
test suit #5 and 6 are wrong
cool
Nice problem!
Read the description carefully!
The Oder of Coins is matter
This problem emphasizes our comprehension on the problem rather than our ability to code.
I think it checks both
test5 and 6 are false answer
yes,me too
This test fail =
a = [ 0 1 2 1; 0 2 1 1];
c = 1;
assert(isequal(most_change(a),c))
I don't undersdand why.
The first person = 0 * 0.25 + 1 * 0.10 + 2 * 0.05 + 1 * 0.01 = 0.21
The second person = 0 *0.25 + 2 * 0.10 + 1 *0.05 + 1 * 0.01 = 0.26
So the first person has less money than the second, should return 2.
I'm missing something here?
d = [0.25 0.05 0.1 0.01];
[c idx]= max(sum((a.*d)'));
b = idx;
This works but how to optimize it to reduce the size.
function b = most_change(a)
a(:,1)=a(:,1)*0.25;
a(:,2)=a(:,2)*0.1;
a(:,3)=a(:,3)*0.05;
a(:,4)=a(:,4)*0.01;
c=a(:,1);
d=[]
for i=1:length(c)
d(i)=sum(a(i,:))
end
[M,idx]=max(d)
b=idx
end
why does this not work?
a(:,2) should be multiplied with 0.05
a(:,3) should be multiplied with 0.1
since they are not ordered in the question
thank you
Look at the description carefully, there is a trick.
The correct value matrix is [0.25 0.05 0.1 0.01].
Nobody would do this:
[ .25; .05; .10; .01; ]
If you are going to demonstrate a concept, do it right - minus tricks!
exactly !
Thanks
[~,b]= max(sum((a.*[.25,.05,.1,.01]),2))
a = [0 1 0 0; 0 0 1 0];
c = 2;
How is the second one the one with the highest money? The first one has $ 0.10 whereas, the second has 0.05.
a = [ 0 1 2 1; 0 2 1 1];
c = 1;
Here too! How is the first one higher? When you evaluate, you get $ 0.21 for the first one and $ 0.26 for the second.
Sneaky
It's a trap! read carefully.
tricky order
For this problem the two tests of the test suit have issue
Test5:
a = [ 0 1 2 1; 0 2 1 1];
c = 1;
Test6:
a = [0 1 0 0; 0 0 1 0];
c = 2;
The solution should be other way around.
Why is Code 5 and Code 6 so gross?
I don't see how the test problems 5 and 6 are correct, they are displaying the answer the lower monies.
it is so funny that the order is not exactly according to the "right order".
it is so funny that the order is not exactly according to the "right order".
you need more seriously read the question.
Take care of the value of dime = $0.10, nickel = $0.05. The order in the matrix is just replaced. silly trick
the expected results of the test case 5 and test case 6 are not correct.
Clumsy version that seems OK in Octave, but then so did the earlier more elegant one
Jerks. Every fast food place I've worked (and there's been a bunch) orders the register sequentially.
Is this about coding Matlab or trick questions? If the rest of these are trick questions I'll go somewhere else.
I thought Cody was about testing your Matlab skill. This task with its deceitful wording is far from being that as I imagine most of the people got the code right but failed at Test 5 and 6 due to the purposeless and illogical coin order swap in the first sentence of the problem.
Thx, it took me a shit ton of time figuring that out. Every time I red the question I did not notice that bit so thx.
Tricky
Test 5 and 6 are wrong in their answers please check
Tips:in that order! in that order!!!
fell for it!
just look around for the solutions
mandovà
Test 5 and 6 combinations are not correct. Test 6 similar to the example given at the starting, but both answers are contradicting.
c'est nul
It's important to read carefully the description, maybe it should be ordered so to not create confusion.
why my procedure can not pass the test5 and test6
Yes,me too.
It's a trap!
read carefully.
very easy
gj
This is wrong or not?
Very good. It is very interesting to solve it. The most problem is to optimize the program and guarantee the small size.
Very sneaky!
Could anybody help guide me in the right direction?
The current code fails on the "c" outputs
"b" or "c" are just arguments of isequal() function. It does not matter.
As the tag says, "notice the rignt sequence of money!"
Test 5 and 6 change the variable and appear to be incorrect when denoting which person has more money. Ex. b = 2 b/c .26 is more than .21, but the answer shows c = 1
%my code runs perfectly in matlab
function b = most_change(a)
b = 1;
clc
quarter = 0.25;
dime =0.10;
nickel =0.05;
penny =0.01;
y = [quarter,dime,nickel,penny]';
out = a*y;
[u v] = max(out);
b = v;
end
Test suite #2 and 3 incorrect
They are correct.
This is a trick question.
As far as I can see it fails in 5 and 6 because the assertion answers provided are wrong. Furthermore in test 1-4 the assertion answer is called b then in 5-7 c
This is a trick question. The test 6 says that
% Now go back and read the problem description carefully.
Very deceptive question. see through the test suite before submitting
Point 5 and 6 works on my station with b=1 and 2. I don't understand what is the "c=1/2" in the solution ?
I'm happy to get to 1-line solution.
on Test 5 and 6, to be honest I cheated,because they dont check correctly!Shame on you MATLAB
Be careful the order is quarters, nickels, dimes, and pennies. Not quarters, dimes, nickels, and pennies
Start with the following...
a*[25 5 10 1]'
and you know how much each person has.
I dont know why my solution doesnt satisfy all the test inputs. If someone could explain what I did wrong that would be great.
Nickel comes before dime. Also, there is a five person test, so you need k=5.
Not sure the test suite is correct on this problem. If I have 1 dime, two nickels and a penny then I will have (21 cents). If I have two dimes, a nickel and a penny, I will have 26 cents. So the second is larger, but the test suite is testing that the row should be 1. Both 5 and 6 seem off.
Hello I am a South African newbie, and this is how I solved it
function b = most_change(a)
a(:,1) = 0.25 .* a(:,1);
a(:,2) = 0.05 .* a(:,2);
a(:,3) = 0.1 .* a(:,3);
a(:,4) = 0.01 .* a(:,4);
a = a';
vecsum = sum(a);
vecsum = vecsum';
[M,I] = max(vecsum);
b = I;
end
Almost had it!! The ordering has nickel and dime switched. So just change v to
[.25 .05 .1 .01] and you're done.
it has failed for a = [ 0 1 2 1; 0 2 1 1] , says 1st person has more money. How is 0.21>0.26 ??
Read the problem carefully in terms of the order of the coins.
Hm, I did not read the descrption that carefully the first times ;)
test 5 and test 6 are wrong.
the true answer of test 5 is 2, and for test 6 it is 1.
You have inverted dime and nickel in your problem wich produce an inconvenient mystake.
Good, but the little trick felt a little underhand
Problem is good, but tet cases are contradict to conditions.
That was a dirty trick, lol. It was a forehead slapper once I saw it.
this runs well on matlab and octave. Am I missing something?
"n_rows=size(a)(1,1)" should read "n_rows=size(a,1)"
Thank you! I'm getting confused between this and octave syntax:)
Test 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...
Similarly, for Test 6 is wrong
a(1, :) = $ .10;
a(2, :) = $ .05;
so output should be 1
poorly written problem
For some reason, regexp manages to interpret the string input as an anonymous function, call this function and return the output. I must say I don't really understand how this works. Why does regexp call the function when comparing the two strings? Is it a bug?
Anyway, this is really ugly code; it would be fine if the Cody team would remove the possibilities to use regexp, str2num etc to score cheap size points.
Agree with Jacob
i also agree with jacob
Definitely agree with Jacob too!
Thanks for the feedback. We will discuss and see if we can ban the use of regexp
Thanks for your attention, Aditya Jain :-)
function ans = most_change(a)
m=[0.25 0.10 0.05 0.01];
[r,c]=size(a);
for i=1:r
c(i)=sum(a(i,:).*m);
end
for j=1:r
if(max(c)==c(j))
ans=j
end
end
all are correct but fails 5 ,6 test suit pls help me
Read the comments for the problem.
To the one who made this problem:you are not really a very good person...O(∩_∩)O
The author is not a good person.....
Nice work!!
Can you explain how this works please?
This is only a (shameless) trick to save one cody point... hint: double('á-Z ')=[225 45 90 9]=9*[25 5 10 1]
Brilliant idea! How did the conversion to character even occur to you?
in Test,case 5 and 6 is wrong,a=[ 0 1 2 1; 0 2 1 1],c should be 2,that means person 2 has more money
Watch out, they've inverted the dimes and nickels in the input vector!
do I get it right: The apostophe after 0.01]' is double interpreted? once to convert row vector into column vector and once to end a string? what am I missing? Thanks for clarification
The double apostrophe inside the string becomes a single apostrophe, i.e., just a transpose.
Thank you, but wouldn't that mean that the apostophes are unbalanced (which for some reason they are not) -> 3 apostrophes, 1 transpose?
The 1st and 4th apostrophes denote the beginning and end of the character string, and the 2nd and 3rd represent a single apostrophe inside the string. A pair of apostrophes together is what you use to get one apostrophe inside a string. It's just one of those awkward computer things.
Thanks a lot, Tim.
Doh! I should have known that this is a matrix multiply!
Annoying obfuscation regarding the input variable's coin 'column ordering'. Shame on you, Cody.
why does this work, but simply having the vector [0.25; 0.05; 0.1; 0.01] does not?
Any ans for Neural Nomad's question. Pls give some reasoning.
str2num evaluates to that vector, so just putting in the vector works also. But Cody just thinks that this code is "shorter": evaluating a function with one argument is less nodes than concatenating 4 values.
Although I appreciate the effort, "size" calculation is B.S. It should calculate time it takes to run the function.
the last suite test is flawed
test 5 is wrong.
Not yet corrected.
The final test case solution is incorrect.
The test # 5 is still wrong.
Test 5 is wrong, (c=2)
Is test case 5 correct? 1 -> 0.21, 2 -> 0.26!!
No 5. Test suite is wrong. For the matrix
[0 1 2 1; 0 2 1 1]; the correct answer is 2 and not 1 as indicated in the test suite.
Why does the second row have more change than the first in
a = [ 0 1 2 1; 0 2 1 1];
Does this setup not mean that row 1 has
0*0.25 + 1*0.05 + 2*0.1 + 1*0.01=0.26
whereas row 2 has 0*0.25 + 2*0.05 + 1*0.1 + 1*0.01 = 0.21 < 0.26?
What am I missing?
question: should not problem 5 (a = [ 0 1 2 1; 0 2 1 1]) have b=2 as the correct answer instead (0.21 vs. 0.26)?
scratch that, I misread the order as 'quarters, nickels, dimes, pennies" instead of 'quarters, dimes, nickels, pennies'...
You did not misread. The order still appears with nickels before dimes at the point where the order is specified (not in the list where values are given).
Test case #5 should have b = 1. This is rather annoying. In addition to the "Remove consonants" problem actually looking for removal of vowels, Cody needs some serious work before it's ready for prime time.
I fixed the last test case and pushed a re-score. Very sorry for the confusion.
:))
why does this has a lower score than when using [0.25 ; 0.10 ; 0.05 ; 0.01] ???
The test suite wasn't sufficiently rich. I've added some tests, so now this fails.
wrong solution, says which person has the most coins, not the most money
What about
a = [ 1 0 0 0;
0 0 4 0];?
Ditto, it appears the test case(s) don't catch this one.
Yes, this solution returns the person who has the most coins, not the most change.
I've added to the test suite to help close this loophole.
11226 Solvers
927 Solvers
Find perfect placement of non-rotating dominoes (easier)
291 Solvers
283 Solvers
Find the sides of an isosceles triangle when given its area and height from its base to apex
751 Solvers
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!