# Enigmatic Code

Programming Enigma Puzzles

## Enigma 1486: 1 in X chance

From New Scientist #2648, 22nd March 2008

I put some or all of the 15 red balls and some or all of the 6 coloured balls from a set of snooker balls into a bag and calculated that there was a 1 in X chance that the first two balls that I picked out at random would both be coloured, X being an integer.

If I had put one more red ball into the bag there would have been a 1 in (X + 1) chance that the first two balls that I picked out were both coloured.

How many red and how many coloured balls did I put into the bag?

[enigma1486]

### One response to “Enigma 1486: 1 in X chance”

1. Jim Randell 25 November 2012 at 9:40 pm

The following Python program runs in 36ms.

```from enigma import irange, printf

# record solutions
s = []

for C in irange(2, 6):
pX = None
for R in irange(1, 15):
# what is the chance of drawing two reds?
(X, r) = divmod((R + C) * (R + C - 1), C * (C - 1))
if r == 0:
printf("[R={R} C={C} X={X}]")
if pX is not None and X == pX + 1:
s.append((R - 1, C, X - 1))
pX = X
else:
pX = None

if len(s) > 0:
printf("SOLUTIONS:")
for (R, C, X) in s:
printf("R={R} C={C} X={X}")
```

Solution: Initially there were 9 red and 6 coloured balls in the bag.

This site uses Akismet to reduce spam. Learn how your comment data is processed.