8 kyu
Price of Mangoes
9,491 of 32,649AartiK1
Loading description...
Fundamentals
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.
This comment has been hidden.
You changed the name of the solution function. In the initial code you are given, the function is named
mango
. It has to stay this way, you cannot change it.you have changed the function name
it should be 'mango'
Terrible description.
No idea what I'm being asked to do.
You are asked to calculate the total price of the mangoes given the quantity and price of the magoes. There is a sale on the mangoes, where you get 3 mangoes for the price of 2.
It's all right in the description.
"where you get 3 mangoes for the price of 2"
or 2 for 1 if you like
and some mangos are arbitrarily free!
Its all right there in the description!
"2+1" is not the same as "get 2, pay for 1". "2+1" is three: two paid, one free.
There's nothing arbitrary about it.
I'm glad we agree.
I feel sorry for your local greengrocers.
Nice and easy, good practice and examples.
Great, another math question.
Dart translate
Approved
Bad description
It's been 4 months and nobody has stepped up to change it. I'm going to close this issue. Feel free to submit a fork of the kata with your improved description.
It was challenging to discern specific areas for improvement based on this comment.
Ah, the irony of criticizing inaction while simultaneously embodying that exact same inaction. Your call to 'step up' seems to apply just as much to yourself as anyone else.
Same for you, so?
Updated.
I was hoping they would do it. Now they have learned that by making some drama, someone would come along and fix it for them.
I thought the description was fine. I had no intention of changing it.
Can't believe I used my little brain to figure out the math formula for this
Interesting kata, but this shouldn't be in the description "(or "2+1" if you like)". It causes confusion.
agree
This comment has been hidden.
you are returing the value returned when you console.log(total). Instead, get rid of the console.log, and simply do "return total"
thank you !!
python new test frame work
Approved
I can't understand the description
Maybe the examples can help you understand?
OP solved it, closing
This comment has been hidden.
OP solved it, closing
the description is not clear
This comment has been hidden.
Great kata. The examples really helped cement what the description was asking. Makes me want to check if real supermarkets honor their "buy 2, get 1 free!"
PowerShell translation
The tester is complaining saying that my program's answer is wrong and should be my program's answer...
Please don't create an issue every time your code is wrong, read this: https://docs.codewars.com/training/troubleshooting#expected-the-same
Your function should return the result, not print it.
how do I do that?
Replace
print
withreturn
.Great idea, but garbage description, spent a solid 10 minutes trying to figure out what was going on.
Can you suggest better wording? I'm open to fixing it.
I'd say you could do something like this:
SITUATION
There's a "3 for 2" offer on mangoes, meaning that every third mango you buy is free.
For a given quantity of mangoes you wish to buy and the unit price of the mangoes, calculate the total cost of the purchase.
EXAMPLES
I added to the description, "meaning that every third mango you buy is free," which I believe makes the prompt for the problem more clear. I also added some text "explaining" what is going on with the examples, but you may remove it if you think it makes the kata too easy or you believe it makes the examples more confusing.
If it wasn't for your (much better) description, I wouldn't have done this Kata (english is not my first language so I was strugling a lot with the amount of missing information this Kata has).
Scala translation
LGTM, Approved!!!
Not a great description. Took me 15 minutes to figure out what the 2 sentence description was trying to say. A simple "buy 2 mangoes get one free" would have made more sense to me anyway.
"Buy 2 mangoes get one free" is misleading too. One of those 2 is free? I think pay 2 and get one free is closer to what is asked. But because I'm not a native english speaker, I don't know what's the usual way of writing that. Is "3 for 2" really that strange?
Well, where I'm from the stores would usually say "Buy 2 get one free". That presumes that the first two are being paid for and the third one is free. For me, saying "3 for 2" is like saying you are getting 3 for the price of two but there would be no free mangoes. Meaning you would get 3 mangoes for 2 dollars but 2 mangoes would not also be 2 dollars but would be $1.34 or something like that. Probably just a difference in how stores around here say things compared to how they say it wherever you are.
Yes, probably. Here they have all kind of "3 for 2", "the second at half price" and many more.
I though of adding the $ sign to the examples, but I don't know if that would be better or not:
Seeing the examples again, if you buy 2, you don't get one free, see the first example. Only if you grab 3, you get one of those free.
Yes, I think adding the $ might be helpful.
Check again.
Yeah I stared at it for five minutes before giving up and reading the comments. Even the 'examples' don't clarify much. I think I'll be skipping this kata.
What's what you don't understand?
@Chrono79 It's just generally confusing and not well explained. I would consider re-writing the entire desription and making the examples more clearly match the description. It is still confusing. Like, is it 3 for the price of 2, or are there free mangoes involved or what? It's just too vague.
What's the difference between 3 for the price of 2 and buy 3, pay 2 get 1 free? The examples are clear imho. For every 3 mangoes you buy, you only pay 2 and get 1 free.
I was able to figure it out eventually. I mean no offense, it's just not clear when you first read it and look at the examples. But I completed it.
No offense taken, now that you solved it, do you have a suggestion about how would it be clearer?
C Translation (author inactive).
Approved some time ago
The examples are poor and misleading.
Misleading how? Added some more examples.
Previously when I made this comment these were the only 2 examples listed:
mango(3, 3) ==> 6
mango(9, 5) ==> 30
but with the new examples that have been recently added, my point is now moot. Problem is fixed. Thank you for the additional examples. They make a big difference.
This question needs more documentation and example test cases than what there currently are. Both test examples have some multiple of 3 and so it is not possible to see without undocumented submission what happens when there are say 4 or 7 mangoes.
Agree.
Ruby 3.0 should be enabled.
Enabled in this fork
Nice and easy but description should tell us customer don't have to always get extra mangoes. it would help to avoid confusion for beginners, who are assuming customer always gets 3 for 2. (considering test examples are only showing examples when customer always gets free mangoes).
This comment has been hidden.
All this "int" business does not makes sense to me with my Python background. I think this Kata is optimized for C++ but not for Python. The randomn tests did not work for me at all.
444 people has solved it in Python, there are several different solutions too (using libraries and not using them).
For some reason, I can pass both of the provided test cases, but when submitting, there's other random test cases that don't show up in tests or when I log the parameters to the console. :(
This comment has been hidden.
Description updated.
Resolved.
i don't get what i need to calculate(my english is not so good sorry)
It'd be really helpful to note the "price" is the price of each mango. Otherwise, it's unclear whether it refers to the price of 2, 3, or each.
Thanks
Description updated.
I REALLY don't get the system they use here - they give 2 TEST objects and both of them pass with my code, but when I try to Submit - there goes a THIRD test, witch i can not see, and it fails... WEIRD ---> how can i fail/win at test that I can't even see? :) Help...? :(
Usually, when a test fails, the log tells you "why" it failed (it is descriptive enough, usually meaning in general that for certain inputs a given result is expected).
You must understand the requirements. If you understand the requirements, then you can add your own tests (it is highly encouraged to do so). If you cannot add more tests, then probably you didn't understand the requirements at all.
If you fully understand the requirements, then you will be able to write a function that passes all tests (as long as these are correctly written).
I agree with you that it is annoying :D
Anyhow, just put this inside your code and you will see for what numbers it is failing. You can do this for other exercises as well ;-)
print(quantity) print(price)
This comment has been hidden.
This comment has been hidden.
Resolved: Not an issue.
My code should work, but when I press submit, it gives errors in the case of high numbered inputs I think? What could be the problem
Could you post your code so I can have a look and give you a hint?
This comment has been hidden.
This comment has been hidden.
@Xaotic, You can see the hidden message when you reply this comment ;-)
Okay, let me see
Xaotic, you should try integer division. In python you can force integer division with
//
So I've just passed the basic tests, but I keep failing the random ones. Is my thinking incorrect? If the quantity of mangoes is divisible by 3, then the price is 2/3 of what you would normally pay, am I right? e.g. you buy 18 mangoes 1$ each, you pay 12 or 300 mangoes 3# each, you pay 600 If this is correct, then why should 1131522 equal 754551?
The problem doesn't say it, but it's priced so that you must buy a quantity of three to get the discount. For example, you want four mangoes so you get three for the price of two plus one for regular price.
still, why exactly should 1131522 equal 754551?
1131522 what? Mangoes? And at what price per mango? If it's for python or javascript, I just checked the test cases and they're working fine.
Actually, I don't know, that was the error message I got. anyway, I'll try to rewrite my code.
I can't see the logic or the desired answer for the test
quantity = -1, price = 1
.Ignoring the dubious idea of counting a negative number of objects, the required value doesn't seem to be -1, 0 or 1, which are the only
Int
values that could possibly make sense?This kata might make more sense as
-> Maybe Int
.</serious>
Of course, if the price is negative, you may wish to decline the 3-for-2 offer, so as to maximize your profit.Which language is that for? I've only write the Python one which doesn't have that issue
Hi,
@AartiK1: it's Haskell. @AppSynergy: This is because of QuickCheck. I agree that negative values don't make much sense. I'll need to figure out how to let it produce only non-negative values.
QuickCheck and I aren't the best friends yet :)
Regards,
suic
Fixed.
C++-Translation kumited!
Please check it and approve. Thank! ;)
This comment has been hidden.
I just checked the test cases again and they're fine. You might want to check your code again. 3rd test case: quantity is 2 and price is 3 => total price = 6 4th test case: quanity is 7 and price is 3 => total price = 15
This comment has been hidden.
What bonus? We'r calculating the total cost of mangoes. The offer is that for every 3 mangoes you buy, you only pay the price of 2. Each mango cost £3 => if you buy 2 mangoes it will £6 If you were to buy 3 mangoes at £3 each, the total price is still £6. 4 mangoes at £3 each => total price = £9 and so on. Let me know if this makes sense
C#-Translation kumited!
https://www.codewars.com/kumite/57abb5ea72292d3548001956
Please check and approve it!
Haskell translation kumited.
Ruby translation submitted and let me know if you either want to take my Ruby code, adapt it a bit into JS or just me to write random test codes.
Cheers^^/
I can't see any Ruby translations...
On the top of this site there is the optionset for the language. There is an entry "Add new". There you will find the open translations, which are still not approved.
Was der Vogelmann sagt!
LOL! :D
Btw: There is a simple translation exercise for you. :D
https://www.codewars.com/kata/57ad85bb7cb1f3ae7c000039
This comment has been hidden.
Just added the random testcases :)
I think the
price
should not equals to 0, isn't it?Didn't spot that, fixed it
Python translation kumited.
What does "kumited" mean, please?
Codewars slang: kumited == published.