4 kyu
Prepare the Cocktails
17 of 24bledding
Loading description...
Algorithms
Functional Programming
Performance
Recursion
Set Theory
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.
Javascript translation
This comment has been hidden.
This comment has been hidden.
Thanks!! Translation approved
.
These two could be refactored to use chai's specific "is array" and "array length" checks. (minor suggestion)
Fork with the above suggestion
done
It seems there is a typo in "Simple tests" (in "Basic tests"):
should be
Fork with fix
fork was approved
This comment has been deleted.
Timed OutPassed: 10Failed: ?Exit Code: 1 Test Results: Log ['Liquor', 'Vodka', 'Mint', 'Pineapple', 'Watermelon'] Basic tests Simple tests (5 of 5 Assertions) Impossible cocktails (2 of 2 Assertions) Not enough ingredients (2 of 2 Assertions) Ice: taste = 0 Completed in 9.37ms Performance tests 26^2 ingredients (5 datasets) STDERR Execution Timed Out (12000 ms) Why did my code time out? Our servers are configured to only allow a certain amount of time for your code to execute. In rare cases the server may be taking on too much work and simply wasn't able to run your code efficiently enough. Most of the time though this issue is caused by inefficient algorithms. If you see this error multiple times you should try to optimize your code further.
Your code being too slow is not a suggestion.
26^2 different ingredients though truly a tropical paradise
tropical paradise, performance hell
This comment has been hidden.
The second print there doesn't execute because there are
26^2
ingredients.With that amount of ingredients, currently your code is checking this many possibilities:
Of course, checking all 1 trillion possibilities would be very slow.
Why would that prevent the second print statement from executing though when it comes before the generator expression
Oh, you meant the
print("goal flavour: ", flav)
. I thought you are talking aboutprint(results_list)
.You're right, that's pretty weird.
True, it's quite strange... if I were to take a guess, I would assume this is a symptome of trying to print a dict of this size: while it's useful to see the example tests' ingredients to find the cause of any bugs, it's pretty much pointless on the performance tests, because there's too many ingredients to check.
Actually, it's straight up counterproductive because print statements impact your performance: if I were you, I would remove print statements when I'm going for the submission rather than the example test cases. As stipulated in the kata description, example test cases should be enough to confirm your algorithm is correct, so you shouldn't need to "debug" performance tests.
Yeah, clearly I have to make it more efficient (seems I overestimated the power of generators)
The entire dictionary does print though, but not the int parameters. That's what struck me as weird
Yeah, that's really weird. I tried running your solution and I couldn't get the print statements to work (except for the first one, for some reason. If I remove it, nothing is printed at all). I read the test cases and found nothing that may prevent a print statement from executing... not sure what's up.
I do think we underestimated the difficulty level of this kata. I don't think anyone has solved this kata yet after approval.
Do you think I should raise it to 3kyu?
We can't raise it. It's approved at 4 kyu, the average vote.
As stipulated by the user, their solution is not correct for all scenarios. Random test case generation should prevent solutions that aren't 100% correct from passing.
I added a test that causes their solution to fail consistently (sorry mednoob blud)
I believe this is due to the solution's volatile execution time, not the problem's. I propose you use another ref sol, based on either of the current top solutions (I would pick the slowest of the two to give users some margin). You would gain a stable ref sol and be able to work on making performance tests even heavier.
Good job, now you have a very challenging kata (imo)
True, thanks for the tip!
Is the footnote about resubmitting on timeout still relevant?
I don't think so. A proper solution never times out.
I think it's best if I remove it then.
The current test creates deep copy for each test. Deep copy is not needed, since the values of the dictionary are only ints. Instead, use shallow copy (which is faster than deep copy). Shallow copy can be made using
ingr.copy()
.You're right, thank you for the pointer
Can different ingredients have the same taste?
No, they cannot: all ingredients have unique taste.
Tests sometimes timing out is fine, but tests sometimes allowing unperformant solution to pass is not fine.
I couldn't increase the power of the dataset (my solution doesn't process it in time) but I increased the number of tests (especially of size
26^4
)My solution consistently solves in 4 seconds, and the top solution in 2 seconds. I think you could add a bit more tests. Use these two solutions to verify that you don't go in overdrive with tests.
I still have no idea how you specify bitter sweetness. I thought it was the absolute value of either all positive, or all negative ingredients chosen. But then there are test cases with expected bitter sweetness of 0 and non-0 flavour. How is this possible?
Bittersweetness is the minimum of bitterness (sum of all negative values) and sweetness (sum of all positive values), both taken absolute value.
This comment has been hidden.
True: done, and done.
The test checking code does not behave according to the description. This is your test checking code:
First, description says
but the test code doesn't obey to this.
Second, your description of bittersweetness is really poor: I looked at the description many times and every interpretation I came up with is wrong, until I looked at the test checking code. You should really just put
test_check
in the tests so it is clear how the checking is done.(You'll need to do this anyway, since the actual tests depend completely on
test_check
, but it is inpreloaded
and so user code can modify it before the tests are run.)I can see how the bittersweetness description is unclear but I'm missing why the test code doesn't abide to the sentence you quoted? For example, let's look at example test case #3 from the first testing function (i.e. the test case where ingredients span from
Mormodica
toWatermelon
,target flav = 3
andtarget bittersw = 2
). A viable solution would be tastes[-2, 1, 1, 1, 2]
(or to be more specific, the ingredient names corresponding to those tastes). NoteMint : 1
is used three times. As from kata description, it adds3
units of sweetness in total (once per unit added) and of course the cocktail is valid because there are3
units of mint in the cocktail, and because we count as much as the quantity, we have indeed5
ingredients, as requested.Well, that's another case of misleading description: saying "their taste is counted once per unit. Tastes are unique." is very easily mistaken for "taste should be counted uniquely". Otherwise there is no need to specify that taste is the sum of taste of all ingredients; this is already specified in the 2nd point, and you'd only specify something more if they aren't counted the normal way. And "tastes are unique" really means "every ingredient has different taste".
You're right, I should reword this too. Also, sorry to abuse your patience but, having reworded the kata description to make it understandable even without reading the checking function, could you suggest a way to make it unavailable to the users for overwriting? Does moving its definition from preloaded to the testing code fix this?
Yes, it'll be fine as long as it's defined in the test section instead of preloaded.
Done, thank you very much for your contribute. I'm marking your issue as solved, since it appears I fixed all the problems you pointed out.
Isn't
flav.
should be the sum of all the tastes, and thebittersw.
is the sum of the negative tastes? Or did I miss something in the description?Because the test assertion code is wrong. I'll re-raise it as an issue.
Flav is indeed the sum of all tastes. As Voile had pointed out it was an error in my tests, it should be fixed. However, bittersw is not the sum of negative tastes. You may think of it as a concept similar to (but not equal to) excursion:
Hopefully this was clear enough? If not let me know
You can just say "bittersweetness is the smaller value of bitterness and sweetness". I don't know how you can get this so convoluted.
Right, will do
Done
Testing code should be more robust: it throws an error if it expects a mix to exist but something else is returned.
Also, there is a wrong test:
ingr
should be the object, not the list.Test assertion failure message is clearly incorrect:
All of the issues you pointed out should be fixed now. Thank you for your patience