Interview: solution to this riddle in programming

Clash Royale CLAN TAG#URR8PPPInterview: solution to this riddle in programming
3 men walk into a bar , where they are blindfolded and given a hat each from a set of 3 blue and 3 red hats. Now the blindfolds are taken off and they are asked to identify the colour of their hat. The 1st person sees the other two and is unable to determine that color of his hat, the 2nd person sees the other two and is also unable to determine the colour of his hat. The last person tells them the colour without taking a look at the other two. What colour hat is the last person wearing?
We have to solve this riddle using coding. Can someone help please?
I have no idea what tags to use, and if this is even the right place to post this question. I am really sorry for any inconvenience caused.
Are you sure you remembered this correctly? As stated it is symmetric with regard to exchanging red and blue.
– Henry
1 hour ago
You should probably only tag the language you want to program in so either Java or C, but not both
– Lino
1 hour ago
@Lino The problem has nothing to do with either Java or C. At present it appears to be under-specified.
– EJP
1 hour ago
1 Answer
1
Your problem statement seems flawed: it is symmetric with regard to exchanging red and blue... There is a similar riddle in this Wikipedia page:
Three-Hat Variant
In this variant there are 3 prisoners and 3 hats. Each prisoner is assigned a random hat, either red or blue. In all, there are three red hats and two blue. Each person can see the hats of two others, but not their own. On a cue, they each have to guess their own hat color or pass. They win release if at least one person guessed correctly and none guessed incorrectly (passing is neither correct nor incorrect).
Indeed if you change from a set of 3 blue and 3 red hats to from a set of 3 blue and 2 red hats, there is a solution and you can write a program to find it.
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.
Can you solve the riddle without programming? Some information seems to be missing. E.g. the explicit statement that the three men can see each others hats and the remaining hats. The third person could conceivably tell his own hat color, but with a symmetric problem statement like this, the solution cannot be the name of a color.
– Yunnosch
1 hour ago