[Community Puzzle] Bag of Balls

Coding Games and Programming Challenges to Code Better

Send your feedback or ask for help here!

The very first test case is wrong. Puzzle description clearly explains that the answer is “1:3” while the answer inside the example AND the test case is “1:2”.

So the ratio P(A) : P(!A) is 1:2 (read 1 to 2).

I see an explanation, why the answer is 1:2 there.

Hi there,

Stats are really not my cup of tea. I have a problem with “4-Ultimate test” (and also test 5 but I would at least understand what is wrong with this one)
I tried to stick as much as possible to the concept of taking balls out of the bag.
I think I got a decent algorithm but I might be totally wrong.

Test 4-Ultimate test
inputs:
n=30 total nb of balls
w=10 nb of white balls
s=10 total nb of balls extracted
k=5 nb of white balls to be extracted

I get the following result

P(A)= 10 / 30 (white ball)
x 9 / 29 (white ball)
x 8 / 28 (white ball)
x 7 / 27 (white ball)
x 6 / 26 (white ball)
x 20 / 25 (black ball)
x 19 / 24 (black ball)
x 18 / 23 (black ball)
x 17 / 22 (black ball)
x 16 / 21 (black ball)
P(A)= 5168 / 10015005
P(!A)= 10009837 / 10015005
result: 5168:10009837
expected: 62016:414889

I don’t see what is wrong: is it my fraction simplification or the way I compute the stats ?
Any help will be greatly appreciated !

It’s also possible to draw the black balls before the white (or in any other order like WBBBWB…), you only count one.

1 Like

Ok I got it.
Thanks a lot eulerscheZahl !

Hello this post makes me understood my error for the ultimate test 1

now i have 80 % and the ultimate test 2 that failed…
I can’t undestand my error since the result a nearly similary

60 balls
40 whites
50 balls taken
35 proba 35 whites… ?

i Do
2250829575120 * (C 50 35)
40/60* (white balls)
39/59*
38/58*
37/57*
36/56*
35/55*
34/54*
33/53*
32/52*
31/51*
30/50*
29/49*
28/48*
27/47*
26/46*
25/45*
24/44*
23/43*
22/42*
21/41*
20/40*
19/39*
18/38*
17/37*
16/36*
15/35*
14/34*
13/33*
12/32*
11/31*
10/30*
9/29*
8/28*
7/27*
6/26*
20/25* (blacks balls)
19/24*
18/23*
17/22*
16/21*
15/20*
14/19*
13/18*
12/17*
11/16*
10/15*
9/14*
8/13*
7/12*
6/11
my result
1235750079647531:7896812518143536 => 0.15648719996
expected result
134976:862537 => 0.15648719997

i can’t undestand why those result are so closed if i m wrong
any clue will be very lovely !
thx

I use Window’s Calculator to do this division, got
0.15648719996939269532056443461388

So the last few digits are 9997 when simplified to the same number of digits as yours.

1 Like

yes but i can’t undestand the ratio found (134976:862537) compared to mine, how the result could be so much factorized

There could be a loss of precision in the middle of your calculation.
What language are you using?
What data type are you using to do the calculation?

2 Likes

I use javascript,
I only do the multiply on the numerator and denominator;
Then i m looking for the largest common divider and divide all…
I m not sure to lose precision using multiply… but you may be right

You could try using BigInt to verify the result. The correct fraction should be able to be reduced to two smaller integers.

2 Likes

You are the winner, is use BigInt() for javascript and it works now…
Thx you @java_coffee_cup !

1 Like

I have success on all test cases – so efficiency is now OK. I fail on validator 2.
As far as I can tell, I’ve dealt with all divide by zero cases so I don’t think I’m generating an error.
Would appreciate some guidance on where to look/what to improve.
Thanks!