Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- times = 1000000
- count_1 = 0
- count_all = 0
- for _ in range(times):
- balls = [math.floor(random.random()*2), math.floor(random.random()*2), math.floor(random.random()*2)] # set balls to 0 or 1 at random
- # pick first ball at random and remove it from balls
- first_pick_index = math.floor(random.random()*3)
- first_pick = balls[first_pick_index]
- balls = balls[:first_pick_index] + balls[first_pick_index+1:]
- # pick second ball at random and remove it from balls
- second_pick_index = math.floor(random.random()*2)
- second_pick = balls[second_pick_index]
- balls = balls[:second_pick_index] + balls[second_pick_index+1:]
- if first_pick == 1 and second_pick == 1:
- count_all += 1
- if balls[0] == 1: # if last ball is 1
- count_1 += 1
- print(count_1, count_all)
Advertisement
Add Comment
Please, Sign In to add comment