Remove 'c' hats from 'n' people - PrismoSkills



Remove 'c' hats from 'n' people - PrismoSkills

Puzzle: N people in a room are wearing C hats where C > 0.
A person wearing the hat cannot know that he is wearing a hat but can see the others if they have hat or not.
If hat can be removed only at 12:00 noon, how many days it would take for all people to get rid of C hats?

Solution: Let us say C = 1.
The only person wearing the hat can see that no one else is wearing a hat and he also knows that C > 0
Hence he can easily conclude that the only person wearing the hat is himself and C = 1.
So he can remove the hat on first day itself.


For C = 2, there will be two people wearing hats (Let us call them Jack and Jill).
Both Jack and Jill see the other person wearing the hat and since they only know C > 1 (not the exact value of C),
each one will assume that they themselves are not wearing hat, thinking C is indeed 1.
So both of them will not remove the hat on first day.
Let us see from Jack's perspective on second day.
On seeing that Jill is still wearing her hat, Jack comes to realize that she did not remove her hat
because she was also seeing someone with a hat. But Jack can see that there is no one except Jill that is
wearing a hat. This means that Jill must be seeing Jack wearing a hat and so he should be removing his hat on day 2.

The same argument applies to Jill and she also realizes on day 2 that she is also wearing a hat because of which Jack
assumed on day 1 that he was not wearing any hat.
So she also removes her hat on day 2 itself.


For C = 3, three people are wearing hats.
By same logic as C=2, they do not remove hats either on day 1 or day 2.
On day 3, each one of them realizes that the 2 hat wearers they see did not remove their hats on day 2 because
they were also seeing two hat wearers on day 2.
This will help those 3 people understand that they are themselves putting a hat too and that C=3.
So all 3 would remove their hats on day 3.


Continuing in this fashion, for C hats, the day on which all hats will be removed is day C.

Read full article from Remove 'c' hats from 'n' people - PrismoSkills


No comments:

Post a Comment

Labels

Algorithm (219) Lucene (130) LeetCode (97) Database (36) Data Structure (33) text mining (28) Solr (27) java (27) Mathematical Algorithm (26) Difficult Algorithm (25) Logic Thinking (23) Puzzles (23) Bit Algorithms (22) Math (21) List (20) Dynamic Programming (19) Linux (19) Tree (18) Machine Learning (15) EPI (11) Queue (11) Smart Algorithm (11) Operating System (9) Java Basic (8) Recursive Algorithm (8) Stack (8) Eclipse (7) Scala (7) Tika (7) J2EE (6) Monitoring (6) Trie (6) Concurrency (5) Geometry Algorithm (5) Greedy Algorithm (5) Mahout (5) MySQL (5) xpost (5) C (4) Interview (4) Vi (4) regular expression (4) to-do (4) C++ (3) Chrome (3) Divide and Conquer (3) Graph Algorithm (3) Permutation (3) Powershell (3) Random (3) Segment Tree (3) UIMA (3) Union-Find (3) Video (3) Virtualization (3) Windows (3) XML (3) Advanced Data Structure (2) Android (2) Bash (2) Classic Algorithm (2) Debugging (2) Design Pattern (2) Google (2) Hadoop (2) Java Collections (2) Markov Chains (2) Probabilities (2) Shell (2) Site (2) Web Development (2) Workplace (2) angularjs (2) .Net (1) Amazon Interview (1) Android Studio (1) Array (1) Boilerpipe (1) Book Notes (1) ChromeOS (1) Chromebook (1) Codility (1) Desgin (1) Design (1) Divide and Conqure (1) GAE (1) Google Interview (1) Great Stuff (1) Hash (1) High Tech Companies (1) Improving (1) LifeTips (1) Maven (1) Network (1) Performance (1) Programming (1) Resources (1) Sampling (1) Sed (1) Smart Thinking (1) Sort (1) Spark (1) Stanford NLP (1) System Design (1) Trove (1) VIP (1) tools (1)

Popular Posts