Ten prisoners, ten hats
Description:
Ten prisoners under sentence of death, numbered 0
to 9
, are to be given a chance to avoid execution:
A hat will be placed on the head of each prisoner, each hat has a number between 0
and 9
(the prison has a large supply of each hat number, so several prisoners may have the same hat number). Each prisoner can see the numbers on the hats of each of the other prisoners but they cannot see their own hat. Each prisoner must try to guess the number on their own hat. They cannot communicate with each other; all they can do is to write on a piece of paper what they think is the number on their hat.
If any prisoner guesses correctly then all death sentences are commuted, but if none of the guesses are correct then all prisoners will die.
Can you devise a strategy for the prisoners which would guarantee their survival?
Implement your strategy as a function:
guess :: [Int] -> Int -> Int
The first parameter is an array of 9 numbers - the numbers on the other prisoners' hats.
The second parameter is the number identifying the prisoner.
In the tests, the function will be called once for each prisoner and will return the guess for the hat number of that prisoner. If any of the returned guesses is correct then the test is passed, otherwise it fails.
Similar Kata:
Stats:
Created | Dec 2, 2022 |
Warriors Trained | 4 |
Total Skips | 0 |
Total Code Submissions | 1 |
Total Times Completed | 0 |
Haskell Completions | 0 |
Total Stars | 0 |
% of votes with a positive feedback rating | 0% of 0 |
Total "Very Satisfied" Votes | 0 |
Total "Somewhat Satisfied" Votes | 0 |
Total "Not Satisfied" Votes | 0 |