An intelligent trader travels from one place to another with 3 sacks having 30 coconuts each. No sack can hold more than 30 coconuts. On the way, he passes 30 check points. At each check point, he has to give one coconut for every sack he is carrying. What is the maximum number of coconuts that he can have with him at the end of his journey?
He will have 25 coconuts with him at the end. The trick is to reduce the number of sacks as you pass checkpoints. The first 10 checkpoints require 3 coconuts each, which empties his first sack. The next 15 checkpoints require 2 coconuts each, which will empty his second stack. Now, he is left with 1 sack and 5 more checkpoints. So, the 5 checkpoints will take 1 coconut each. Therefore, he will be left with 25 coconuts.
There are n coins in a line. (Assume n is even). Two players take turns to take a coin from one of the ends of the line until there are no more coins left. The player with the larger amount of money wins.
Would you rather go first or second? Does it matter?
Assume that you go first, describe an algorithm to compute the maximum amount of money you can win.
Note that the strategy to pick maximum of two corners may not work. In the following example, first player looses the game when he/she uses strategy to pick maximum of two corners.
Example 18 20 15 30 10 14
First Player picks 18, now row of coins is
20 15 30 10 14
Second player picks 20, now row of coins is
15 30 10 14
First Player picks 15, now row of coins is
30 10 14
Second player picks 30, now row of coins is
10 14
First Player picks 14, now row of coins is
10
Second player picks 10, game over.
The total value collected by second player is more (20 + 30 + 10) compared to first player (18 + 15 + 14). So the second player wins.
Going first will guarantee that you will not lose. By following the strategy below, you will always win the game (or get a possible tie).
(1) Count the sum of all coins that are odd-numbered. (Call this X)
(2) Count the sum of all coins that are even-numbered. (Call this Y)
(3) If X > Y, take the left-most coin first. Choose all odd-numbered coins in subsequent moves.
(4) If X < Y, take the right-most coin first. Choose all even-numbered coins in subsequent moves.
(5) If X == Y, you will guarantee to get a tie if you stick with taking only even-numbered/odd-numbered coins.
You might be wondering how you can always choose odd-numbered/even-numbered coins. Let me illustrate this using an example where you have 6 coins:
Example
18 20 15 30 10 14
Sum of odd coins = 18 + 15 + 10 = 43
Sum of even coins = 20 + 30 + 14 = 64.
Since the sum of even coins is more, the first player decides to collect all even coins. He first picks 14, now the other player can only pick a coin (10 or 18). Whichever is picked the other player, the first player again gets an opportunity to pick an even coin and block all even coins.
If you were to put a coin into an empty bottle and then insert a cork into the neck, how could you remove the coin without taking out the cork or breaking the bottle?
Push the cork into the bottle and shake the coin out.
Swaff was traveling in an elevator, being cool, when he suddenly heard the cord supporting the elevator snap. Being the cool guy that he is, he knew of a myth where if you could jump at the right time, you could possibly be able to survive a plunge in an elevator.
Now, when Swaff was a boy, he spent all of his math classes making fun of his female teacher's moustache. He never paid attention, so he was a tad bit slow in his mathematical calculations. He did, however, have a very bizarre talent, in which he could tell the exact speed he was traveling. That came in pretty lucky today.
Swaff knew he was falling at an even rate of 50 miles per hour. When the cord snapped, he was exactly 110 feet above the ground. He knew that he must jump at the right time to have any hopes of surviving.
Now, after doing the math, please tell me when Swaff jumped.
He never did. By the time Swaff figured out that he would have to jump in 1.5 seconds, he would already be dead. Not even the best of mathematicians could do all the math needed in 1 and half seconds. Swaff fell to his death.
Your friend pulls out a perfectly circular table and a sack of quarters, and proposes a game.
"We'll take turns putting a quarter on the table," he says. "Each quarter must lay flat on the table, and cannot sit on top of any other quarters. The last person to successfully put a quarter on the table wins."
He gives you the choice to go first or second. What should you do, and what should your strategy be to win?
You should go first, and put a quarter at the exact center of the table.
Then, each time your opponent places a quarter down, you should place your next quarter in the symmetric position on the opposite side of the table.
This will ensure that you always have a place to set down our quarter, and eventually your oppponent will run out of space.