Challenge (08/21/2020)

We post one challenging problem here every week. Solution due is 11:59 PM every Friday. We offer awards to two responders. 1. The first one with the right solution. 2. The correct solution with fewest code statements.

If we get only one correct solution, we will skip the award for the fewest code statements.

You need to create an account in this club in order to participate in this competition. The solution can use one of these three languages: Java, Python, JavaScript. You can submit your solution to this topic. Make sure your name and email account are in the end of the solution.

If you want that we indent your code correctly, please submit your code to this challenge along with a screenshot of your code in your IDE or your code file as an attachment. Remember you still need to submit your code as text here. Thanks for your participation.

Problem: Bob, Jack and Tom are good friends. Bob likes red ball, Jack green and Tom blue. In the beginning of each month they put 10 of red, green and blue ball each into a box so the box has 30 balls (the box is emptied in the beginning of each month before they add 30 balls to it). Every time they pull three balls out from the box. If these three balls are of three different colors, they will play in the house of that person who pulls the ball. The three balls are returned to the box. If two or more balls pulled out are of the same color, then they go to the house of the person who likes this color to play. They will put these three balls aside (not returning them to the box). They three take turns to pull the balls (Bob, Jack and Tom in this order). In August 20, 2019, there are still 4 red balls and 2 blue balls in the box after 10 pulls. Can you tell me how many times they played in Bob’s house in max in August by then? Write the scripts to show me all the possibilities in the first 10 pulls.

14 thoughts on “Challenge (08/21/2020)”

  1. You say that “In the beginning of each month they put 10 of red, green and blue ball each into a box so the box has 30 balls.” Does this mean:

    X) Every month, they add 30 balls of 10 red, 10 green, and 10 blue to the balls left over in the box from previous months?

    Y) Every month, they add enough balls so that the balls in the box equal 10 red, 10 green, and 10 blue?

    Z) At the beginning of the 10 months, they add balls to the box equal to 10 red, 10 green, and 10 blue, then don’t add balls anymore?

    1. Good question. I will update the requirements to make it clear. In the beginning of each month, they empty the box and then add 30 balls to the box, 10 for each color.

      1. Okay, so EACH month, the box is fully restocked.

        My second question is, how do we get left over with 4 red balls and 2 blue balls?

        Are the draws for the balls all in the SAME month (meaning August), meaning the balls aren’t replenished? Or are the balls taken out then replenished every month.

        If it is the second option, then it wouldn’t be possible for there to only be 4 red and 2 blue balls left at the end of August.

        Incidentally, if the first choice is correct, does time even matter here? If we just had a box full of balls (10 red, 10 green, and 10 blue), and then drew 3 balls out of it for 10 times, is this still basically what the question means?

        1. It may be clear to put it this way. Every time you pull out three balls. With 30 balls, you can only pull 10 times. Now you have already pulled 10 times, you still have 6 balls left. It implies that there are two times you pull out three balls of three different colors. In that situation, you have to return the balls back. Say the first day we pull out one red, one green and one blue. You need to play in my house. I have to put the three balls back. The 2nd day, you pull two blues and one green, we play in Tom’s house. These three balls are thrown away. After two pulls, we still have 27 balls in the box.

  2. I have more questions.
    So I wanted to ask about: “If these three balls are of three different colors, they will play in the house of that person who pulls the ball.”

    Does the mean that they choose a random person’s house to play at? Or does it mean that that they play at the person that is picking the ball’s house?

    If they are playing at the person that is picking the ball’s house, is the order of the people that pull the ball set or undefined? If it is set, then who goes first, and could you tell us the order?

    Also, would you like EVERY SINGLE permutation of the balls and their orders, or would plain combinations suffice?

    1. The order to pull the ball is Bob, Jack and Tom. There is no way to say who has pulled the balls of three different colors. That is why the challenge asks for possibility? It could be Bob pulled three balls of the same color. Then they played in Bob’s house. Next Jack pulled three balls of different color and then they played in Jack’s house. After that, every pull would have at least two balls of the same color. It also could be that the first time Bob pulled out 2 red and 1 green. Then they play in Bob’s house. Or Bob pulled out 2 green and 1 blue and they played in Jack’s house. One thing is very certain though. There were two times that the pull had three different colors. So that is why after ten pulls, there were still 6 balls left. Therefore, we know for sure 10 green balls were pulled in the rest 8 times. The minimum pulls that could have to pull 10 green balls is 4: 3 pulls of 3 green and 1 pull of 1 green. That will make it 10. The maximum pulls is 8: 2 pulls of 2 green and 6 pulls of 1 green. To calculate the times they played in Bob’s house, you just need to calculate how many pulls that there will be two red balls and plus the possibility that Bob pulled twice with three different colors.

  3. Okay. I think that the program might be a bit too large-scale.
    Are you sure you want PERMUTATIONS? (Note, PERMUTATION is not the same as POSSIBILITY).
    Or do you want COMBINATIONS? (Note, COMBINATION is also not the same as POSSIBILITY).

    Example Set: {1, 1, 1, 2, 3, 3, 4};

    Permutations of size 3: (1, 2, 3), (3, 2, 1), (2, 1, 3), etc.

    Combinations of size 3: (1, 2, 3), (1, 3, 4), (1, 1, 1), etc.

    In other words, does ORDER matter?

    Do you just want (1, 2, 3), or do you want (1, 2, 3), (3, 2, 1), (2, 3, 1), etc?

    In other other words, do you care about the order in which the balls are pulled in their groups, or do you just care about which balls are pulled in groups.

    1. I am really looking into is the pull result. Let’s say 1, (1,1,1); 2, (0,2,1); 3, (0,3,0). Something like that will help. However, in the example here, the order 1, 2, 3 matters if Bob is the first one to pull and they will stay in Bob’s house.

    1. Can you explain to me what does this permutation mean?
      Plays at Bob’s House: 3; Permutation: [9, 9, 9, 6, 5, 5, 1, 1, 0, 0]
      In the 10 pulls, each time we pull 3 balls. After 10 pulls, there are 6 balls left. This means there are two pulls that have three different colors. In the left 8 pulls, we only pulled 6 red balls. To maximize the possibility that they play in Bob’s house, then these 6 balls must be divided into three pulls so that three pulls will have two red balls. That means they can only play three time in Bob’s house, plus if it is lucky, those two pulls with different colors were all done by Bob. So max will be 5 possible days. I need this possibility

      1. Here is the key for what the numbers represent:
        1 = Red, Red, Red
        2 = Red, Red, Blue
        3 = Red, Red, Green
        4 = Blue, Blue, Red
        5 = Blue, Blue, Blue
        6 = Blue, Blue, Green
        7 = Green, Green, Red
        8 = Green, Green, Blue
        9 = Green, Green, Green
        0 = Red, Blue, Green

        Since the program will give us the permutation in the order in which the balls are drawn, the first set of balls that are drawn is 9. This 9 (as you can see in the key above), represents Green, Green, Green, meaning that the person pulled 3 green balls on turn 1. We have another 9 after that, meaning that on turn 2, the person also pulled 3 green balls.

        As for the 3 balls of the different colors, we have 0 representing them. Furthermore, since we only go to the house of the person the chose the balls when the balls are different colors, and Bob will always go first, as you said here: “The order to pull the ball is Bob, Jack and Tom.”

        So 0 will only count as a visit to Bob’s house when it is in position 1, 4, 7, or 10. As we see in the permutation above, the 0s are at 9 and 10, meaning that we count 1 trip to Bob’s house. Since the only other combinations of balls where we go to Bob’s house are represented with 1, 2, or 3, and we only have two 1s in the above permutation, we see that the total times we visit Bob’s house is equal to 3, which is 1 plus 2, and which the program gives us.

        The max possibility is 5, however in this case we don’t see it as such, because order matters to be able to determine who’s house to go to when the balls drawn are different colors. The max possibility is represented in the permutations that are printed, however since the program prints lines out so fast, you might have missed it.

        If you want me to, I can change it so that the program will only give us combinations of working possibilities, and print the highest possible visit count to Bob’s house.

        1. Yes I care only the possible permutations that make them play 5 times in Bob’s house. There are not that many permutations because we have to make sure we have 4 red balls left. Print out all those permutations.

    1. Let’s analyze these two result in your printouts:
      Maximum possible plays at Bob’s House: 5; Combination: [2, 2, 2, 5, 6, 9, 9, 9, 0, 0]
      Maximum possible plays at Bob’s House: 5; Combination: [2, 2, 2, 5, 8, 8, 9, 9, 0, 0]
      Bob starts first. So the first, second and third pulls are all good for playing in Bob’s house. They are pulled by Bob, then Jack then Tom. From fourth to eighth, all pulls will not go to Bob’s house. They are pulled by Bob, Jack, Tom, Bob, Jack. Tom pulls the 9th and it is of three colors so they play in Tom’s house. Then Bob pulls the tenth and it is of three colors and they play in Bob’s house. So the total times playing in Bob’s house is just 4, not five.

      The actual answers are like these:
      0s must be pulled by Bob and there three 2s

Leave a Reply