Skip to main content
Posts
You are given a unlimited number of coins and 10 pouches. Now, you have to
divide these coins in the given pouches in a manner that if someone asks
you for any number of coins between 1 to 1000, you should be able to give
the amount by just giving the pouches. You are not allowed to open
pouches for that.
How will you do it?
Know here the only efficient way to do that!
Source
What was the challenge?
Once again here binary number system comes in handy. Similar kind of use of binary system in day to day life is here! Another intelligent use is here! We are already provided 10 pouches which is exactly equal to the number of bits required to represent any number from 1 to 1000. Let's number the pouch as Pouch 0 to Pouch 9. So we need to group coins in 10 pouches like below.
Pouch 0 : 1
Pouch 1 : 2
Pouch 2 : 4
Pouch 3 : 8
Pouch 4 : 16
Pouch 5 : 32
Pouch 6 : 64
Pouch 7 : 128
Pouch 8 : 256
Pouch 9 : 512
Now if somebody asks us for 30 coins then we should give Pouch 4, Pouch 3, Pouch 2, Pouch 1. (11110) That's the binary representation of 30 if we assume Pouches as a bits. If another asks for 828 (binary - 1100111100) then we should give Pouch 9, Pouch 8, Pouch 5, Pouch 4, Pouch 3,
Pouch 2.