Post Reply 
Little math problems September 2018
09-20-2018, 12:54 PM
Post: #2
RE: Little math problems September 2018
Code:
SPOILER ALERT











These are the changes to white and black balls based on the color of the two chosen balls:
WW: W -= 1
BB: W += 1, B -= 2
WB or BW: W -= 1

We can see that number of black balls can only be reduced by 2 thus we end up with 1 black ball.
From now on the number of white balls can only be reduced. Thus we end up with 1 black ball.

Bonus: A Python program that simulates the process.
Code:
SPOILER ALERT











from random import choice

bag = ["W"] * 15 + ["B"] * 13

while len(bag) > 1:
    first = choice(bag)
    bag.remove(first)
    second = choice(bag)
    bag.remove(second)
    both = first + second
    if both == "WW" or both == "BB":
        bag.append("W")
    else:
        bag.append("B")
    print first, second, bag

The result of a typical run:
Code:
SPOILER ALERT












W B ['W', 'W', 'W', 'W', 'W', 'W', 'W', 'W', 'W', 'W', 'W', 'W', 'W', 'W', 'B', 'B', 'B', 'B', 'B', 'B', 'B', 'B', 'B', 'B', 'B', 'B', 'B']
W B ['W', 'W', 'W', 'W', 'W', 'W', 'W', 'W', 'W', 'W', 'W', 'W', 'W', 'B', 'B', 'B', 'B', 'B', 'B', 'B', 'B', 'B', 'B', 'B', 'B', 'B']
B W ['W', 'W', 'W', 'W', 'W', 'W', 'W', 'W', 'W', 'W', 'W', 'W', 'B', 'B', 'B', 'B', 'B', 'B', 'B', 'B', 'B', 'B', 'B', 'B', 'B']
W B ['W', 'W', 'W', 'W', 'W', 'W', 'W', 'W', 'W', 'W', 'W', 'B', 'B', 'B', 'B', 'B', 'B', 'B', 'B', 'B', 'B', 'B', 'B', 'B']
B B ['W', 'W', 'W', 'W', 'W', 'W', 'W', 'W', 'W', 'W', 'W', 'B', 'B', 'B', 'B', 'B', 'B', 'B', 'B', 'B', 'B', 'B', 'W']
W W ['W', 'W', 'W', 'W', 'W', 'W', 'W', 'W', 'W', 'B', 'B', 'B', 'B', 'B', 'B', 'B', 'B', 'B', 'B', 'B', 'W', 'W']
W W ['W', 'W', 'W', 'W', 'W', 'W', 'W', 'B', 'B', 'B', 'B', 'B', 'B', 'B', 'B', 'B', 'B', 'B', 'W', 'W', 'W']
W W ['W', 'W', 'W', 'W', 'W', 'B', 'B', 'B', 'B', 'B', 'B', 'B', 'B', 'B', 'B', 'B', 'W', 'W', 'W', 'W']
B W ['W', 'W', 'W', 'W', 'B', 'B', 'B', 'B', 'B', 'B', 'B', 'B', 'B', 'B', 'W', 'W', 'W', 'W', 'B']
W W ['W', 'W', 'B', 'B', 'B', 'B', 'B', 'B', 'B', 'B', 'B', 'B', 'W', 'W', 'W', 'W', 'B', 'W']
B B ['W', 'W', 'B', 'B', 'B', 'B', 'B', 'B', 'B', 'B', 'W', 'W', 'W', 'W', 'B', 'W', 'W']
B B ['W', 'W', 'B', 'B', 'B', 'B', 'B', 'B', 'W', 'W', 'W', 'W', 'B', 'W', 'W', 'W']
B W ['W', 'B', 'B', 'B', 'B', 'B', 'W', 'W', 'W', 'W', 'B', 'W', 'W', 'W', 'B']
W B ['B', 'B', 'B', 'B', 'W', 'W', 'W', 'W', 'B', 'W', 'W', 'W', 'B', 'B']
B B ['B', 'B', 'W', 'W', 'W', 'W', 'B', 'W', 'W', 'W', 'B', 'B', 'W']
B B ['W', 'W', 'W', 'W', 'B', 'W', 'W', 'W', 'B', 'B', 'W', 'W']
W W ['W', 'W', 'B', 'W', 'W', 'W', 'B', 'B', 'W', 'W', 'W']
W B ['W', 'W', 'W', 'W', 'B', 'B', 'W', 'W', 'W', 'B']
W B ['W', 'W', 'W', 'B', 'W', 'W', 'W', 'B', 'B']
W W ['W', 'B', 'W', 'W', 'W', 'B', 'B', 'W']
B B ['W', 'W', 'W', 'W', 'B', 'W', 'W']
W W ['W', 'W', 'B', 'W', 'W', 'W']
W W ['B', 'W', 'W', 'W', 'W']
W W ['B', 'W', 'W', 'W']
W W ['B', 'W', 'W']
B W ['W', 'B']
W B ['B']

Thanks for the challenge
Thomas
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
RE: Little math problems September 2018 - Thomas Klemm - 09-20-2018 12:54 PM



User(s) browsing this thread: 1 Guest(s)