6 kyu
Power Laws
27 of 77marbiru
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.
python new test framework is required. updated in this fork
This comment has been hidden.
Great kata, howewer I really dont see the point of last test case :
Does anyone see any interest, or any physical or practical meaning to that requirement, given that if (x1,y1) = (x2,y2), there is an infinity of solutions except on the given point...
That forces the user to construct a special case for that very situation (except for lechevalier clever hack but then it would silently yeald a wrong result when x1=x2!=x3...) and makes the solution ugly and bloated IMHO.
Would'nt it be more natural to give two distinct points or throw an exception if x1==x2?
This comment has been hidden.
ah, my bad! Thank you, fixed now
cool :)
hey everyone: I decided to change up the kata so that it gives you two points in the distribution and you have to find a third. I think this is a better way for people to understand what a power law distribution is, but it also makes the kata harder. My apologies to anyone/everyone who already solved this kata and whose solutions are now invalid, sorry about that. Any feedback/suggestions much appreciated as always!
I'm thinking of changing this kata so that instead of giving you the points held by position n and the relationship between position n and position 2n, it just gives you [position, points] stats for two arbitrary positions and has you infer the correct power law relationship from there (then finally prove you have done so by returning the points held by another arbitrary position). It adds a little extra challenge (will make the solution more than twice as long I think), but I think it better captures what power laws are about. Any thoughts?
hey guys -- I can imagine that this kata might run into problems with someone coming up with an equally-correct solution that is just a little different from mine, and which as a result is marked wrong by the checker (e.g. if they do rounding at a slightly different moment and come out with an answer that is 1 point different that would be marked as wrong). Could a more experienced coder help me figure out how to fix the tests so that this doesn't happen? (Or let me know if this isn't actually an issue)? Some possibilities I can think of are rounding the random decimals down to 2d.p. (currently I'm just using Math.random() as-is), or using some kind of leeway on the assertEquals statement (not sure how to do that but I know it exists). Any help/advice much appreciated; I've got no experience with these kinds of issues unfortunately so any fix I did right now would be kind of arbitrary.
You could write a custom test function that only passes if the difference between the actual answer and the reference answer (taken as a positive number, so
Math.abs
it) is smaller than some absolute or relative value.Test.approxEquals
does this, but only allows a 1e-9 relative error; I think you want something a little more forgiving.So calculate a Boolean from
actual
andexpected
, andTest.expect
that. Make sure to supply decent failure messaging, and you're good to go.Would you need an actual code snippet for that, or can you take it from there?
ah, thanks so much, that's exactly what I needed -- I was going to ask for a code snippet but then I realised I could just try it myself and managed it on my own in the end :) I put in leeway of 1% of the reference solution, after playing around a bit with different induced discrepancies; hopefully that's a good-enough compromise to allow different methods to work but without letting "cheat" solutions through, but we'll see what happens as people solve it. thanks so much again for your help.