6 kyu
Help naughty Codewars users cheat by sharing their solutions to katas
46 of 57benjaminzwhite
Loading description...
Puzzles
Mathematics
Logic
Combinatorics
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.
Factor Translation
Looks good.
Well if it's good enough for the lambda-men, it's good enough for me!
Thanks on behalf of all the Factor users, I'm sure both of them will love this :)
Haskell translation
fixes some minor speeling errors in the description
approved
Thanks to both of you; I notice that my personal favourite katas are always the ones that attract the Haskell translators - I wonder if that means I'm supposed to
join the lambda cultdiscover this practical, user friendly language myself >>=</s>
$$$
Just try to make sure you don't wake up the Factor translators
Authoricratus activatae, no issues, enough beta votes -> approved at kyu 6!
and now I expect a joke about factorial(6)
Is it truly a 6 kyu kata? For me it was harder then most of 4 kyus here
werent you listening, it isnt 6kyu, it is (6!)kyu
Apparently there is a subreddit about this:
https://www.reddit.com/r/unexpectedfactorial/
I also found it considerably more difficult than 6, however on finally managing to solve it, I realise that the difficulty was due to how I was trying to solve it.
Tip for any readers: Trying to work out a proof for what the optimal length will be might make this quite a hard (but fun) challenge. Rather, try use other problem solving techniques such as identifying patterns, and working out small cases by hand (eg, from the solution for 4 people, try work out the solution for 5 people). If you think you have an idea, just try it, even if you aren't 100% sure it holds for big numbers.
I think kyu
6
is in itself a hint not to overthink this too much ( like this user did ).Thanks for apprO_oving @dfhwze, I also think it's tough for a 6 but @Kacarott's comment is really good in that case: I'll add it to the description if there are too many rank comments in Discourse.
Small issue: Python fixed tests still call the user solution twice.
Fixed - thanks for the attention to detail!
Also updated the custom
is_sol_list_of_tuples
helper function in tests/preloaded: it was only checking that the first tuple was of length 2 and contained ints; now it checks that all the entries in the solution list are valid.Removed some incorrect tags also.
JS Translation Note that I did not touch the description. Perhaps you should make it language-agnostic after approving this translation. Review it carefully though. I tried to implement the same measures as in Python to avoid helping out hardcoders.
Thanks for translating, and for the effort with the test measures! I'll let someone else review in that case - or I'll ask in Discord this evening if someone can have a look.
Absolutely about the description - upon re-reading now, I want to go over it all again and try to make it much more concise; and I will remove all the language specific stuff in general. Will be updated by this evening :+1:
Keep this in mind when writing a specification in general: Clear, concise, consistent – The three Cs of effective communication
ApprO_oved - I'll keep an eye out for any comments about the kata now that there might be a new wave of JS people.
Also, big updated the description - any comments welcome; also made it language agnostic.
I usually think in Correct, Complete, Concise. Inconsistent can't be correct, and not considering Clear is probably why I get ( sometimes lots ) of Complaints.
Cool kata, pitty only half the beta testers have voted :/
Indeed - maybe I should theme the kata about sharing beta votes instead of solutions!
Perhaps my translation will attract more voters. JS is a sexy language afterall.
I just saw that @monadius solved in Python and also kindly voted, which pushes the kata into approvable; therefore I'm going to ask in Discord if anyone can have a look at your sexy JS translation.
I've got the updated description ready also, which I'll update/edit on main kata once your current translation is apprO_oved.
Very enjoyable puzzle to solve and a very nice description for it! Though, after looking at the other solutions, I feel a bit silly about the naive approach I came up with while trying out stuff with pen and paper.
About the helper functions in preloaded: If I understood your goal correctly, you'd like as little information as possible to leak out in the example tests. Right now the is_valid_solution_list function works on all inputs (even for n > 1000), while is_optimal_length only works for n in [2, 3, 4, 6] and always returns False for other inputs (I also found
is_optimal_length([], 6) = None
). To make it more clear that those functions only work for specific inputs and to stop users from trying to get more information out of them, my suggestion would be to put assertions at the very beginning of them, like so:Aha, thank you for attempting this little kata - as you can see it hasn't been very popular since 2-3 months!
In fact as you can see below, it was my 2nd (I think) ever attempt at writing a kata and I had lots of challenges trying to understand the various comments and designing the tests; I've returned to it a few times since then, every time I find a better way of doing things. Feel free to copy-paste anything if you find it useful.
In effect you are right about the "information leaking" issue; I forget how I originally tried to implement this but with @Voile and @hobovsky and @Madjosz comments + some digging myself through the Python test suite, I learnt about the preloaded code and the various ways to fail tests early.
I really like your suggestion though so I implemented it also - thanks! The preloaded functions now all have such assert messages, while the "grown up" versions in the full test cases work for any value of
n
.By the way - since you seem to have a promising kata-author future ahead of you - I will share my general lesson learnt from this specific kata: it's really difficult to design ones based on "sequences/patterns" because you either have to hide too much (so people complain about not having feedback to debug) or when you give away expected results then people just Google/OEIS the small dataset and find the answer immediately. So that's why I have since tried to avoid doing them.
Anyways, glad you enjoyed this - I wrote it after discovering this problem and felt really proud of solving it myself; people who Google/OEIS these kind of puzzles miss out on the enjoyment of figuring things out just to get +2/3 meaningless Internet Points - I don't understand them!
Thanks for sharing your insights, advice taken! I am just realizing that there's kata authoring is a lot more work than expected but it's a great learning experience and very rewarding!
Now, you got to apprechiate the irony of having to go through all this trouble of cheat-proofing a kata that is about people cheating katas! Anyways, even if it might mean some extra trouble when authoring, I think we shouldn't refrain from having nice things just because a few people might cheat on them. In the end, couldn't people always just create a second account to look up the solution there and then copy it to their main account? So the whole point system is relying on honor regardeless of the efforts we spend to make it cheat-proof, right?
The current way of testing is not very good: it calls user function twice per input, and does not validate user returned value (especially for the second test assertion on length). Then hiding optimal length is pointless as user can return any list and wait until this test assertion passes.
Hi @Voile thanks so much for the feedback; I'll edit the fixed tests so that they are formatted more like the random tests and call the user function only once.
For your second comment, could you explain a bit more as I'm still learning/improving good testing practice: How can I validate the user returned value? Do you mean something like a
except ValueError
for the returned length?Right now, If I try to return any list of the wrong size my test.expect() seems to catch that the user's list is of wrong size so I must be missing something important from the last part of your comment. I've tried searching for examples on StackOverflow but I can't see anything that matches your comment.
Thanks for any suggestions,
The part "[...] does not validate user returned value (especially for the second test assertion on length)." probably means that some solutions which are potentially work in progress or return a value of expected type but not correctly structured, fail badly.
This solution is not unexpected, but crashes badly:
Some other solutions are less probable, but also do not seem to be handled gracefully. I would not consider them this much of an issue, because I think it's more difficult to return them accidentally, with a WIP solution, but properly structured tests should handle them and not crash:
return [(1,2,3),(2,3,4)]
andreturn [[1,2],[2,3]]
andreturn "foo"
are not recognized as invalid.return [[1],[2]]
fails badlyThis comment has been hidden.
This comment has been hidden.
This comment has been hidden.
@Voile - @hobovsky - @Madjosz
I've updated all of the various outstanding issues on this kata, now that I'm more experienced with the test framework.
Actions taken: briefly, since comment thread was getting quite long:
completely rewritten tests to incorporate what Voile said about testing twice/and stopping tests early to avoid leaking information.
created a detailled helper function to deal with hobovsky 's comments about gracefully handling most commonly expected incorrect solution types
better implemented Madjosz advice about hiding length values; fixed tests now show expected values for a limited number of test cases only, but don't allow for Google-able general approach to be discovered
Some other minor changes to test layout and description also updated.
I'll close this issue now due to no further comments since 2 months; please open new one though if there are any problems with this new updated version of the kata.
Thanks again to all 3 for your help and patience with me back then, as I was just starting out.
Test block description lists ranges as open sets (like
5 random tests with 7 < n < 20
) but the range is actually inclusive.Hi @Voile - thanks, good catch; I have edited to inclusive ranges.