473,395 Members | 1,368 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Black or White

kadghar
1,295 Expert 1GB
Picture this:

There are n guys, where n can be any number. This n guys are in a line so they can't see anyone behind them, but they can see everyone in front of them.
The bad guys put a hat on everyone, the hat can be black or white (at random, so there can be n white hats or there can be n black or any possible combination).

Every guy can see the hats of the guys in front of him, but he cannot see his own hat or any behind him.

They start asking from behind their hat's color (the first one will be the one who can see every hat but his). If they guess their hat color, they're set free, if not... =( they get killed.

Fortunately they're a well trained group and they manage to survive all (actually their strategy is not perfect, there's a chance that one of them get killed), can you tell what the strategy is??
May 31 '07 #1
14 2265
Darryl
86
I imagine the first guy is the one that may get killed since he has no clue about his hat, but can tip off the others to theirs.

If there are an odd number of black hats he says black and if there is an even number he says white.

No matter the outcome, the man in front of him should be able to determine his hat because he knows there is an even or odd number of black hats and depending on what he sees in front of him can guess. ex. if he knows it's even and see 3 black hats, he's wearing a black hat or if he knows it's odd and sees no black hats he is wearing a black hat...etc
May 31 '07 #2
eragon
431 256MB
you said that ALL survived? well, theres a 50/50 chance that the first guy lives, so, i think, to get all of them to live, the guy on the end is or did one of two things:

A) He tells all the other people their hat colors and guesses about his. He guesses correct, and is set free...

B) The first guy is superman, he tells all the other guys their hats, and he guesses about his. He guesses wronw, ohwever, because he has super powers he runs while the bullets bounce off him and flys all the other men to safety.

3) They all run like hell and hope they live... :p

----------------------------------------------------------------------------------------------

Theres 3 kinds of people in the world, those who can count and those who cant...

---------------------------------------------------------------------------------------------

Sincerely,

Eragon

PS: Woof says the cat...
May 31 '07 #3
eragon
431 256MB
another thing, how can you see ALL the hats in front of you, unless theres like 3 people in the line... wouldht the other heads block out your view??? :)
May 31 '07 #4
kadghar
1,295 Expert 1GB
you said that ALL survived? well, theres a 50/50 chance that the first guy lives, so, i think, to get all of them to live, the guy on the end is or did one of two things:

A) He tells all the other people their hat colors and guesses about his. He guesses correct, and is set free...

B) The first guy is superman, he tells all the other guys their hats, and he guesses about his. He guesses wronw, ohwever, because he has super powers he runs while the bullets bounce off him and flys all the other men to safety.

3) They all run like hell and hope they live... :p

----------------------------------------------------------------------------------------------

Theres 3 kinds of people in the world, those who can count and those who cant...

---------------------------------------------------------------------------------------------

Sincerely,

Eragon

PS: Woof says the cat...
I liked more Darryl's answer, was like the one i was especting, (its of course a problem of odd an even numbers). Anyway, the superman's idea is great.

And i'd rather say there are 10 kinds of people, those who now binary and those who not.
May 31 '07 #5
eragon
431 256MB
i really cant type today, wronw and ohwever... yed, odd and even is good, but you also said and i quote "...Random..." so, what if, say, theres 8 people and 4 white hats and 4 black hats? or what about 6 black hats and 2 white hats? visa-versa. then odds wont matter, the guy will think wrong and *imitates slitting throat* hes dead...

lol, nice binary joke...

sincerely,

Eragon

PS: The dog goes meow...
Jun 1 '07 #6
kadghar
1,295 Expert 1GB
i really cant type today, wronw and ohwever... yed, odd and even is good, but you also said and i quote "...Random..." so, what if, say, theres 8 people and 4 white hats and 4 black hats? or what about 6 black hats and 2 white hats? visa-versa. then odds wont matter, the guy will think wrong and *imitates slitting throat* hes dead...

lol, nice binary joke...

sincerely,

Eragon

PS: The dog goes meow...
Hi Eragon.

Actually Darryl's answer is preety nice. if you analize it, you will see that it doesnt matter how many black or white hats there are, if they are 4 and 4, or 6 and 2 or 8 and 0, it's the same method. or if they are any combination, because the one whose turn is next can count if they are odd or even after listening te answer from the guy behind.

Saludos. y que tengas buen día.

Kad
Jun 1 '07 #7
Hi,

Here is what i think their streategy would be.

There are n People and n Hats.

The first person will count the number of Black hats and White Hats. Now if n is odd then both the numer of black and white hats will either be even or odd. And if n is even then either black hats are even or white hats and vice versa.

Now lets say that n is Odd and the first person has to guess what hat he is wearing. Lets say that they all aggreed that the first person will say white hat if all white and black hats are even and he will say black hat if the black and white hats are odd.

lets say the person say white hat.

now the second person will count the black and white hats. the second person knows that including his hat the white and black hat count should be even numbers. if black hat count is odd then the second person is wearing a black hat and if white hat count is odd then he is wearing a white hat.

now the third person knows that one hat is successfully guessed by the second person. so he will now count the black and white hats. if the the black or white hats's even or odd are inverted then the third person is wearing the hat whos even odd is inverted.

this continues for the rest of the people.

Now lets say the person say black hat.

now the second person will count the black and white hats. the second person knows that including his hat the white and black hat count should be odd numbers. if black hat count is even then the second person is wearing a black hat and if white hat count is even then he is wearing a white hat.


Here is what i think their streategy would be.

There are n People and n Hats.

The first person will count the number of Black hats and White Hats. Now if n is odd then both the numer of black and white hats will either be even or odd. And if n is even then either black hats are even or white hats and vice versa.

Now lets say that n is Odd and the first person has to guess what hat he is wearing. Lets say that they all aggreed that the first person will say white hat if all white and black hats are even and he will say black hat if the black and white hats are odd.

lets say the person say white hat.

now the second person will count the black and white hats. the second person knows that including his hat the white and black hat count should be even numbers. if black hat count is odd then the second person is wearing a black hat and if white hat count is odd then he is wearing a white hat.

now the third person knows that one hat is successfully guessed by the second person. so he will now count the black and white hats. if the the black or white hats's even or odd are inverted then the third person is wearing the hat whos even odd is inverted.

this continues for the rest of the people.


Now the above two senarios are surely going to save n-1 peoples life and the first person has a 50/50 chance to live because he is not guessing his hat, he is just giving a signal to the rest to guess their hats.


Now I have to think about the other tho senarios, in which one of the black and white hat count is even and the other one will be odd.

This is really interesting problem. I am trying to save the first person because that might be ME :P.
Jun 1 '07 #8
kadghar
1,295 Expert 1GB
Hi,

Here is what i think their streategy would be.

There are n People and n Hats.

The first person will count the number of Black hats and White Hats. Now if n is odd then both the numer of black and white hats will either be even or odd. And if n is even then either black hats are even or white hats and vice versa.

Now lets say that n is Odd and the first person has to guess what hat he is wearing. Lets say that they all aggreed that the first person will say white hat if all white and black hats are even and he will say black hat if the black and white hats are odd.

lets say the person say white hat.

now the second person will count the black and white hats. the second person knows that including his hat the white and black hat count should be even numbers. if black hat count is odd then the second person is wearing a black hat and if white hat count is odd then he is wearing a white hat.

now the third person knows that one hat is successfully guessed by the second person. so he will now count the black and white hats. if the the black or white hats's even or odd are inverted then the third person is wearing the hat whos even odd is inverted.

this continues for the rest of the people.

Now lets say the person say black hat.

now the second person will count the black and white hats. the second person knows that including his hat the white and black hat count should be odd numbers. if black hat count is even then the second person is wearing a black hat and if white hat count is even then he is wearing a white hat.


Here is what i think their streategy would be.

There are n People and n Hats.

The first person will count the number of Black hats and White Hats. Now if n is odd then both the numer of black and white hats will either be even or odd. And if n is even then either black hats are even or white hats and vice versa.

Now lets say that n is Odd and the first person has to guess what hat he is wearing. Lets say that they all aggreed that the first person will say white hat if all white and black hats are even and he will say black hat if the black and white hats are odd.

lets say the person say white hat.

now the second person will count the black and white hats. the second person knows that including his hat the white and black hat count should be even numbers. if black hat count is odd then the second person is wearing a black hat and if white hat count is odd then he is wearing a white hat.

now the third person knows that one hat is successfully guessed by the second person. so he will now count the black and white hats. if the the black or white hats's even or odd are inverted then the third person is wearing the hat whos even odd is inverted.

this continues for the rest of the people.


Now the above two senarios are surely going to save n-1 peoples life and the first person has a 50/50 chance to live because he is not guessing his hat, he is just giving a signal to the rest to guess their hats.


Now I have to think about the other tho senarios, in which one of the black and white hat count is even and the other one will be odd.

This is really interesting problem. I am trying to save the first person because that might be ME :P.
actually it doesnt matter if one is even and the other not, the first person has to say if white are even, and it really doesnt matter the other color, they'll just have to count the white hats. (or black, color isnt important).

And if you're the first one, the best strategy is to buy a horseshoe or a 4 leaf clover.
Jun 1 '07 #9
DeMan
1,806 1GB

lets say the person say white hat.

now the second person will count the black and white hats. the second person knows that including his hat the white and black hat count should be even numbers. if black hat count is odd then the second person is wearing a black hat and if white hat count is odd then he is wearing a white hat.

now the third person knows that one hat is successfully guessed by the second person. so he will now count the black and white hats. if the the black or white hats's even or odd are inverted then the third person is wearing the hat whos even odd is inverted.
I think this is not quite right, ig the hats were even then there are either "Odds and odds" or "evens and evens" between the black and white, the person will see an odd number of one and an even of the other, but does not know whether tho adjust the odd to be even or the even to be odd (by adding his own)....?
Jun 1 '07 #10
DeMan
1,806 1GB
The bloke at the back says "I've got a white hat, and the dude in front of me has a black (or white) hat"

If he's right (about the white) he lives, if he's wrong he dies,

but now the next one knows he has black hat and can say "i have black (or white - see above) hat and the dude in front of me has a black (or white) hat"

etc
Jun 1 '07 #11
eragon
431 256MB
my head hurts... :(

Eragon
Jun 1 '07 #12
Darryl
86
These guys are being held by ruthless terrorist, they are not allowed to tell the others their hats, they are not allowed to say anything except the answer to the color of their hat.
Jun 3 '07 #13
bartonc
6,596 Expert 4TB
If this is not a linear line, but a circular line, all possibilities are known.
Jun 3 '07 #14
eragon
431 256MB
Picture this:

There are n guys, where n can be any number. This n guys are in a line so they can't see anyone behind them, but they can see everyone in front of them.
The bad guys put a hat on everyone, the hat can be black or white (at random, so there can be n white hats or there can be n black or any possible combination).

Every guy can see the hats of the guys in front of him, but he cannot see his own hat or any behind him.

They start asking from behind their hat's color (the first one will be the one who can see every hat but his). If they guess their hat color, they're set free, if not... =( they get killed.

Fortunately they're a well trained group and they manage to survive all (actually their strategy is not perfect, there's a chance that one of them get killed), can you tell what the strategy is??

i think its a linear line and the dude in the back guesses and lives. man, how would it feel to be that person... id look up. cant they just look up? unless they have beanies, then they cant really look up to see their hats, why cant they just <take off their hats? i need coffee....... c[_]
Jun 5 '07 #15

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Stijn Goris | last post by:
Hi all, I want to make a coloured picture black and white when a user moves its mouse pointer over it. I just don't want to store a coloured an black and white (grayscaled) version on the...
12
by: Penna Elabi | last post by:
How do I create a style sheet with black background and white text?
7
by: JCL | last post by:
I have a winform and on this winform, I have a WebBrowser control. Users can browse the web through this form. Is there a way that I can make web pages show up as grey scale pages, with the color...
7
by: marfi95 | last post by:
I'm trying to implement some code in vb.net to allow the user to adjust the brightness or contrast on an image (through the use of a slider) that is already black & white in the bitmap. I have...
5
by: kaosyeti | last post by:
how can i get my report to print all in black when i have a control with conditional formatting to change the font color about 10% of the time it shows up. i've been trying to find a way to format...
1
by: Sandy | last post by:
Dear Pythonic People, I recently discovered SciTE (1.68) as a programming editor, and I find it just beautiful. Small, fast, elegant and beautiful. I particularly like syntax highlighting...
1
by: retheeshnewage | last post by:
I have a doubt in php.I wrote a php program to convert colour Images to balck & white.It is working fine with JPEG files and PNG files.When it comes to GIF files I am not getting the colour...
3
by: Muddasir | last post by:
hi all i need to upload an image and if that image is coloured i need to convert it to black and white image ... till now i only uploaded images ... simple.. have no idea how to do this...
9
by: George | last post by:
C with 2 sprained hands. I would nlike to emulate the t4 encoding scheme using the following graphic: * * * * * * ***** o O o o
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.