7 kyu
Barista problem
1,419 of 3,014Stefan30
Loading description...
Fundamentals
Sorting
View
This comment has been reported as {{ abuseKindText }}.
Show
This comment has been hidden. You can view it now .
This comment can not be viewed.
- |
- Reply
- Edit
- View Solution
- Expand 1 Reply Expand {{ comments?.length }} replies
- Collapse
- Spoiler
- Remove
- Remove comment & replies
- Report
{{ fetchSolutionsError }}
-
-
Your rendered github-flavored markdown will appear here.
-
Label this discussion...
-
No Label
Keep the comment unlabeled if none of the below applies.
-
Issue
Use the issue label when reporting problems with the kata.
Be sure to explain the problem clearly and include the steps to reproduce. -
Suggestion
Use the suggestion label if you have feedback on how this kata can be improved.
-
Question
Use the question label if you have questions and/or need help solving the kata.
Don't forget to mention the language you're using, and mark as having spoiler if you include your solution.
-
No Label
- Cancel
Commenting is not allowed on this discussion
You cannot view this solution
There is no solution to show
Please sign in or sign up to leave a comment.
excellent kata
Hey there!
Many many thanks for the kind words! I am really glad you enjoyed it!
All the best!
Thanks for this nice kata! Enjoyed solving it.
Hey there! Thanks for trying it out! Glad you enjoyed it. Make sure you also check out the next one in the series. Cheers!
Stop whining, all good here. Understanding complex text comes along side with programming. Business people don't talk programming :) Besides logic for the solution is implementable in excel...
Anything is implementable in Excel if try hard enough :DD
@avermakov You have a point here! XDDD
@PR3SS F Thanks for the kind words. Hope you enjoyed the Kata. Make sure you give the next challenge in the series a try! Cheers!
Rust prototype is
Vec<u8>
whereas tests use&[u8]
.Fixed
Thanks for pointing it out. Also, akar-0, thanks for the fix. Cheers!
Not quite a clear description. I would write task like: You as a barista have a list of coffee orders. You need to find a way to serve coffee for all people in the list in such a way that all people all together are waiting as little time as possible. And you need to calculate this time.
Rust error in tests with function declaration. "error[E0308]: mismatched types" It looks like slices are being passed in and not Vec.
Hmm, thanks for reporting it. I am not familiar with Rust, maybe somebody else can help.
for rust, the tests should look like this
Fixed (the input type was not correct in initial code).
Thank you for the fix. Cheers!
The description should be concise, not written like a small novel.
If it is not written "like a small novel" it would spoil the entire point of the challange as it would just tell you what you have to do. You have to figure out what to do on your own, while trying to solve this real life problem.
Solved in C++. I enjoy it. Description is clear, no comments.
Thanks for trying it out. Cheers!
1kyu katas' descriptions are easier to understand than this one, I'm not a native english speaker but still.
you goddamn right
Problem description issue.
Sorry mate, but in real-world logic, the sum doesn't make any sense since (i.e.) the third customer only waits for previous orders only once.
You can't mark this as an issue just because it does not follow real world logic. The challange states what is expectes you to do, if you want to do it, you do it, if not, skip the challange. Thanks for trying it out though! Cheers!
I'm having enough of this english-language-related trick question. I'm here to learn coding after all...
I'll just skip.
(such a shame for an interesting problem tho)
Well, it is pretty tricky to put into words what the challange expects you to do, but that is exactly why there is a fully detailed example, explaining that you must add all the waiting times. Thanks for trying it out though. Cheers!
Please, can you check my code, because I test it in two different compilers, and I get expected result. But here in your compiler it print wrong result for random tests. For no order, small order and large order it prints correct.
This is not a kata suggestion (= suggestion of improvement of the kata). You should say which language you are using, and other stuff (see
Docs
tab on the left pannel).C++ translation, random tests follow python generation
https://www.codewars.com/kumite/6310c8d0e5da9e0016a2ef67
Thanks for the translation. Cheers!
The description is bad and needs to be re-written by a native English speaker. It's very ambiguous and almost every comment is complaining about this exact problem. Here is a suggestion to put at the top:
tl;dr Return the total value of the waiting times for all customers, so that the waiting time is the least it could be. (ie. Customer 1's wait + Customer 2's wait + Customer 3's wait...)
Simple
Why every next coffee takes less time to make? What is going on?
Where do you see that?
Logic of counting time is false. Total waiting time has to be the last customer
s waiting time, but not the sum of all. Because waiting time of previous customers is already counted in the last customer
s waiting time/ So, [4, 3, 2] has to be 13 (4+2 + 3+2 + 2), but not ((4) + (4+2 +3) + (4+2 + 3+2 + 2))The kata clearly says "...in such a way that the sum of all the waiting times of the customers..." and "..., return the minimum total waiting time.". So, you don't count only the waiting time of the last customer but the sum of all customers. And that's exactly the point of this kata.
These are more ESL problems than math or programming problems. Really wish a native speaker would go through and make all of these less ambiguous.
D translation
thanks for the challenge got my brain to work :D
You are very welcome! Thanks for trying it out! Cheers!
This comment has been hidden.
Thanks a lot! Cheers!
I don't understand why in the notes says that the list [4, 3, 2] should return 26, but in the example says that the same list [4, 3, 2] should return 22. If anyone could help me I would apreciate becouse it doesn't make any sense for me.
As @Elfein7Night pointed out, what you see in the notes may not be correct, it just shows the logic that you would apply if you were to choose that specific order. Cheers!
This comment has been hidden.
This comment has been hidden.
!
Change the
barista manager
link to the main kata url (https://www.codewars.com/kata/624f3171c0da4c000f4b801d) instead of the JS solutions page.Fixed. Thanks for pointing it out. Cheers
Probably applies to many translations, though I specifically encountered it in the Lambda Calculus translation:
Zero-time drinks should be explicitly (dis)allowed and/or included in the example tests and/or shown in the failing test message.
Otherwise, a fun kata, thanks.
Python (original language), COBOL and PHP don't generate zero values. JS does, Haskell I don' know. About C, I think there's an error and
coffees[i] = rand() % 40 % 1;
would rather becoffees[i] = rand() % 40 + 1;
. Currently random tests generate zeros only arrays in this language.COBOL and C tests print the input in case of failure.
C error has been fixed
Hello, thanks for your tips and kind words related to the kata. Printing the random input test cases can be done by the warrior himself, so I thought that it was not really necessary to print them in case the warrior fails them. About the 0 time coffees, they are mentioned in the next challange in this kata series. Cheers.
Because 0 time coffees are only generated in JS I will try to remove them.
Ah, Lambda Calculus is a special case here – you can't print anything directly from within LC. It has no builtin log method. Tests can provide an indirect escape hatch, but only if the tester deliberately programs one in. :-)
Well that seems kind of hard to debug in this case XD. Thanks for the tips.
where in the conditions it is written about a random test?
Almost every kata if not actually every kata on CodeWars has random tests. Pointing that out in the description seems pointless. Cheers!
sorry but it doesen't make any sense the description
Feel free to propose a better one, although almost 1000 people solved it.
I think there needs to be a summary sentence in the example paragraph. The total wait time is 26 minutes becuase customer1(4 minutes), customer2(9 minutes), and customer3(13 minutes). It took me a while to figure out how to the total was 26 minutes.
Well that is the point of solving a CS problem right? Figuring out how to get to the desired result by using some sort of data already provided to you. Cheers!
C Translation kumited, thanks.
Thanks a lot. Cheers!
@rowcased: can you have a look at the issue raised by glebec above and my answer. Seems random tests are incorrect.
got it, thanks
I really don't understand the description.
coffees = [20,5] -> 32
Cust 1 20 = 20
Cust 2 20+2+5 = 27 not 32
or
Cust 1 5 = 5
Cust 2 5+2+20 = 27 still not 32
Must be miss understanding something, or it's not clear, I'm missing a calculation or magic number?
You must accumulate all the waiting times.
First customer is waiting 5 minutes, second is waiting 5 (of first customer) + 2(maintanance) + 20(his own waiting time). So accumulated time is 1 customer time(5) + 2 customer time(27) = 32
You must accumulate all the waiting times: The first customer waits 5 minutes and the second waits 27 minutes. All this is in the description, please read it carefully, I'm not even sure I should answer you, I'm giving away the solution...
This comment has been hidden.
You just didn't read carefully: the sum of all the waiting times of the customers. And then it is explained clearly in the note.
This comment has been hidden.
Please see there how to format your code properly: https://docs.codewars.com/training/troubleshooting/#post-discourse
OP solved it, closing
COBOL translation.
Thanks for the translation. Cheers!
The description is misleading... Ive spend way much time to try to understand what do You mean in this kata.
Feel free to propose something better.
I have taken this kata to the next level, so if you want to see what other challange you have to face as a barista, check this out: https://www.codewars.com/kata/624f3171c0da4c000f4b801d/solutions/javascript
Lambda Calculus translation
I did some minor cleaning up of the description. Hope you don't mind.
( Don't worry that the solution is a lot longer than in other languages. This is expected in LC. )
It's great actually, now it looks a lot tidier with all the test cases in one code block. Thanks for the translation! Cheers!
Translated to PHP. Happy coding!
Test description should be changed to 'Sorry, but the smallest waiting time possible is: 0'
You are right, the "copy-paste" is to blame here XD. Thanks a lot, I fixed it :
test.assert_equals(barista([]),0,'Sorry, but the smallest waiting time possible is: 0')
it should be 'return' rather than 'print' ;-)
Nice detail you spotted here, you are right, "return" seems to be a better word XD. Thank you, I changed it.
Sorry coders. Apparently I broke something in the back, I will fix it ASAP.
Fixed.
Haskell translation
Thank you for the translation, I have also replied to you in the translations private chat.
( JS, possibly others )
Random tests may generate an empty list of coffees. That means there should be a fixed test for this edge case.
Thank you for the tip, I will try to account for that empty array ASAP. Thanks again!
Fixed! I added a minimum of 1 to the "number_of_numbers" generated. Thank you.
Actually, an empty queue of orders seems a valid input with a defined output. (
wait([]) => 0
)The haskell translation tests this case, so I'd have to fix that if the specs are updated so an empty input is defined to be out of spec. ( That's not hard, but right now it's explicitly being tested, on purpose. )
Ok. Well then it will remain a possible case and I will see if it behaves correctly in JS, so no need to update the Haskel translation.
I have added the edge case and also updated the description of the kata.
But will we get our raise ?!? :P
XDD
Hello everyone. I have just added a JavaScript version of this Kata so it is now available for JS coders. Happy coding guys!
Can you help me with understanding this kata? Why in total time we are doubling time for coffee we already made? If I need 5 min for 1'st, 3 min for 2'nd and 2 min break between, I can do this with 10 min in total whatever order i choose...
Hello. The keyword here is that you need to compute the total waiting time, keyword = waiting. So yes, you are right, you can brew those coffees in 5+3+2 = 10 minutes, but the first customer has to wait 5 minutes, the second one has to wait for the first customer to receive his coffee so 5 minutes and after that he will wait 2+3 minutes. This is all because you only have 1 brewing machine. Just think about how much time the second customer has to wait, or the third, or the fourth.
There's no point in custom error messages which poorly duplicate the
test.assert_equals
behavior. Also, random tests should usetest.assert_equals
.Since you and I are now contradicting each other I suppose this is my cue. Do you mean that it should be doing this?
And, what is it that
test.assert_equals
does better? Please educate me because I did not only suggest it but I do it myself as well.Apparently I'm not getting a response. I'm not opposed to using
test.assert_equals
as shown above but I'm as of yet not convinced that it is superior and it's probably not going to look better to a custom-formatted error message. My point is, I'm not trying to cancel out FArekkusu's suggestion here. So if anyone is waiting for someone to stand down then consider me to have done that.Well, Thank you both for the valuable infomartion. I am going to go back to the standard
test.assert_equals
, so I can fix this issue and maybe get the kata approved. I really hope nobody is going to get upset with this decision. Thank you again for the help.@Stephan30: you apparently forgot to update the sample tests ;)
@Blind4Basics Hello. Thank you for the tip, but I am not really sure I understand what you mean. The sample tests are made with
test.assert_equals
or maybe this is not what you meant? Thank you again :)No that's ok. I misunderstood your previous message.
No problem.
Now it doesn't say what the test was though x)
All fixed tests show the same wrong custom error message
"Sorry, but the smallest waiting time possible is: 0"
.You are right. Now it should work. Thank you for pointing that out.
I think it'd be better if the kata was only about finding the minimum total waiting time rather than additionaly comparing it to some value and returning a formatted string - this step has nothing to do with the actual task, it adds zero value/complexity to the kata overall, and it takes more code to return the correct string than to calculate the waiting time which is really dumb. Also, assuming this kata gets approved, it'll be very annoying to translate it to (and solve it in) lower-level languages like C.
Actually I also got this suggestion from the Discord community, and I think it is valid. I will make the required changes. Thank you for the tip.
Alright, I made the changes. Thank you for the help.
typos:
--
Random test cases are under
describe('Fixed Tests')
--
Test output doesn't show what input was used. (both random and fixed tests) The test framework doesn't really facilitate displaying what input was used (other than perhaps the
it
header) but what you can do is to do the comparison yourself and provide a custom error message totest.fail
and otherwisetest.expect(True)
if the comparison succeeded, something like:--
that
sol
global var is an abomination, and, the test isn't entirely fixed if it's calling a reference solutionThank you very much for your feedback.
Thanks again for the help.
I believe I fixed every issue that was found. If you find anything else please do not hesitate to write about it here. Thank you for the help, now I just need to wait for the kata to get approved. All the best.
Sample tests should import the solution explicitly.
You are right. I have imported the solution explicitly for the test cases, but forgot about the sample ones, my bad. Thank you for pointing that out.
I'm confused. You said we can brew the cups in any order we want, so why can't we brew the 3-cup first and the 5-cup second for a total waiting time of 3+2+3+5?
no-one said you can't ;-)
This comment has been hidden.
Ok. To me, it seemed implied by the wording of the phrase "the total waiting time is", since the total waiting time is exactly what the solver must determine. I think there might be less potential for confusion if it read something like "the total waiting time if brewed in this order (which may not be optimal)".
(Sorry, I'm trying to mark this question as resolved, but it's saying I'm not authorized to.) (edit: because Stefan30 already marked it resolved while I was typing this lol)
Its already been resolved by author
The kata is tagged as "puzzle". Some potential for confusion ain't a bad thing here :) EDIT: in fact, it's not tagged as such, so nevermind xD
"Ok. To me, it seemed implied by the wording of the phrase "the total waiting time is", since the total waiting time is exactly what the solver must determine. I think there might be less potential for confusion if it read something like "the total waiting time if brewed in this order (which may not be optimal)"."
Alright, you are right. I will change that ASAP. Thank you for the tip. :)
The random input array grows more and more huge with each test - is this intended?
No this was not intended. Thank you for pointing that out. It should be fixed now.
"Wrong output"
is not a useful custom error message.Thank you for the tip. I have changed that message, but I think it might take some time until it takes effect.
The user can modify the input.
You should either provide a copy of the data to the user or calculate your expected answer upfront.
I am sorry, this is my first kata so there are a few aspects that I don't fully understand about this process of creating katas. That being said, I am not sure where the issue is, the user can modify the example test cases, but he can't modify the rest of the test cases right? Thanks again for the help :).
No, the user can modify the input itself, meaning that all random tests will always pass / fail (depends on modification)
What happens is you have input, you feed it to user, but if he modifies it, your own solution gets the modified input, not the actual one you intended, meaning all random tests can go haywire
Alright, now I get it, but I am not really sure how to prevent that from happening. Could you please point me to a website or something similar from where I could learn how to fix this. Thanks a lot.
I believe I have fixed this issue. I hope it works now. Thank you for the help.
What to do when answer is 0 ?
Hi, thanks for the feedback. Do you mean when you have 0 minutes left ( or 0 extra minutes :))?
When coffe making time is same as total time alloted / when
answer == 0
? What should be done in that caseAlright. In that case you should print: 'Yes, I did it! I had just the right amount of time'. I will fix this ASAP. Thanks for the feedback.
Solution should be imported explicitly.
Thank you for the tip. I have imported the solution explicitly. I hope this is what you wanted to say: from solution import barista
No random tests.
All solutions are failing since you added random tests. Did you change anything else or are the random tests not ok?
Thank you very much for your tip. I have added random tests. I hope they work.
Indeed I had some problems with the random tests, so that is why they did not work for a few minutes. I hope they do now.
If you have any feedback for this kata, please feel free to tell me about it. Thanks to everyone for their help. Have a great day/evening. :)