Skip to content
Related Articles

Related Articles

Puzzle 11 | (1000 Coins and 10 Bags)
  • Difficulty Level : Medium
  • Last Updated : 08 Mar, 2021

A dealer has 1000 coins and 10 bags. He has to divide the coins over the ten bags so that he can make any number of coins simply by handing over a few bags. How must divide his money into the ten bags? 

Solution: 

The idea of filling coins in the powers of 2 can be get from the condition that was given the question that each bag can be given or not given, that is we are not allowed to open the bag and give some coins. So we can represent each bag as each place value which takes either the value of 0 or 1. For example if we have to give 7 coins then it is nothing but 0000000111 the last 3 digits of 1 represents that those 3 bags whose place values are 1,2,4 are to be given to give 7 coins. Remember that each bag should be either given or not given that means there are only 2 choices to us, which has similarity with the numbers in base 2 where each digit has only 2 values either 1 or 0.
We can fill coins in the 10 bags in increasing order of 2^n where n varies from 0 – 8, filling the last bag with all remaining coins as follows: 

1 = 2^0 = 1 

2 = 2^1 = 2 



3 = 2^2 = 4 

4 = 2^3 = 8 

5 = 2^4 = 16 

6 = 2^5 = 32 

7 = 2^6 = 64 

8 = 2^7 = 128 

9 = 2^8 = 256 

10 = remaining coins = 489 

Now, the dealer can make any number of coins just by handing over the bags. 

As, 
number 0f coins needed = some bag 1 + some bag 2 + ….. + some bag n 
example: 
519 coins = bag 2 + bag 4 + bag 8 + bag 16 + bag 489 

Factorization algorithms other than powers of 2 are costly on computer systems. Please share any other information. Any person working on cryptography can share more details. 

Source: https://www.geeksforgeeks.org/forums/topic/1000-coins-and-10-bags/ 

Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above. 

Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.

My Personal Notes arrow_drop_up
Recommended Articles
Page :