6 kyu
Statistics in Kata 2: AND case - Ball bags
54 of 190powderham
Loading description...
Statistics
Probability
Arrays
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.
happened again.... x/
I am going to fix this and other issues today.
This was fixed
The description uses an incorrect terminology: "mutually exclusive events" should be replaced with "independent events" everywhere. The joint probability of mutually exclusive events is always 0. But the joint probability of independent events is the product of probabilities.
I believe I replaced all occurences.
Thank you!
Python new test framework should be used (Refer this & this for more detail)
test.assert_approx_equals
should be used insteadFixed
Node 12 should be enabled (Refer this and this for more info)
assert.approxEquals
should be used insteadThis was fixed
Ruby 3.0 should be enabled, see this to learn how to do it
Fixed
x(
Who's the jerk who put a link into the description that leads directly to the EDIT PANEL of the other kata...?
x(
:/ ... Fixed.
\o/ (at last...)
This is now faulty for python without replacement
I did the math longhand and it worked fine, but failed the third random case. The expected value was not the correct value based on doing the math long form.
Any idea why that might be?
problem was: (ball_probability([['yellow', 'green', 'yellow', 'yellow', 'yellow', 'yellow', 'green', 'green', 'blue', 'green', 'green', 'blue', 'red'], ['green', 'blue'], False]))
Sounds similar to the problem below?
I suspect you were mutating your inputs, so the resilts for the comparison calculation were not the same when replacement was disabled. An additional Python test had been added to check for mutation.
I have a feeling I am missing something in the explantion. All the test cases work fine, but when I run on random inputs I sometimes get failures when replace is False. So let me talk you through my understanding of one test case (w/o showing the code) (... and as you will see I am not a mathematician so I need dummies guide as explantions!)
The input is [['red', 'yellow', 'red', 'yellow', 'yellow', 'blue', 'red', 'yellow', 'green', 'blue', 'blue', 'green', 'red', 'yellow', 'yellow', 'green', 'yellow', 'blue'], ['blue', 'red'], False]
So I have 18 balls, 4 of which are blue, so P(b) = 4/18 = 0.222.... Since I don't replace the blue that I drew on the first round, I now have only 17 balls, 4 of which are red, so P(r) = 4/17 = 0.235...
So P(b,r,False) = 0.222x0.235 = 0.052, but according to the test, the probablity should be 0.037
Now - where is the flaw? I was hoping writing this would lead me to enightenment, but not the case this time...
Are you mutating the inputs?
You are right, this kata makes no sense. I did manage to solve it, but the description wasn't that great to begin with.
My solution failed one of the random test cases; the kata "expected -0 but got 0". It went through fine when I hit submit a second time.
Translations published :)
I tried to keep your original spirit intact, so same data structure as an input and not too many edge test cases (no balls with less than 2 elements); let me know if everything is ok for you!
Ruby: test arrays need to be
.dup
ed before giving them to the user to (possibly) modify. (Note this includes the sub-arrays too.)Isn't
[]+array
going to copy a monodimensionalarray
anyway? Just asking, as you are certainly more knowledgeable than me in this regard.