Programming Fundamentals
Logic building/ Problem Solving is the most important part of programming fundamentals. Here, I have some questions for you. Read them carefully and try to find their logic by yourself. If you cannot, don't worry answers will be given below each question. Let's start:
Question no. 01:
Suppose you have two containers; 1st container has black balls and red balls. Number of black and red balls in this container is unknown. There might be only black balls or only red balls or any number of black and any number of red balls in 1st container. 2nd container has unlimited red balls. Now the game is that you have to pick up two balls from the 1st container without seeing the balls, after picking out you can see them and follow the following instruction:
i) If both balls you picked up from 1st container are red, you have to place one red ball in the 1st container back.
ii) If both balls you picked up from 1st container are black, you have to place one red ball in the 1st container back.
iii) If one ball is red and other ball is black, you have to place one black ball in the 1st container back.
Now what you have to do is that you have to think on this problem and answer the following two questions:
Q.01: Will the game end?
Q.02: If ends then tell the color of the last ball in the 1st container?
Hint: Involve the concept of even and odd numbers and think in this way. For example: suppose odd number of red and even number of black balls and try to solve it and give answers. Similarly cover all the possible conditions. 2nd container just supplies red balls when required. It has nothing to do with answer.
Answers:
Ans. 01: The game will end.
Ans. 02: Given below:
i) If number of black and red balls are same:
a) If even, then last ball will be red.
b) If odd, then last ball will be black.
ii) If number of black and red balls are different:
a) Any number of red balls, but number of black balls are even, then last ball will be red.
b) Any number of red balls, but number of black balls are odd, then last ball will be black.
iv) If only red balls, then last ball will be red.
Feel free to comment or ask something!
Comments
Post a Comment
Feel free to comment or ask something related to games.