Draft

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.

Algorithms
Puzzles

Similar Kata:

Stats:

CreatedDec 2, 2022
Warriors Trained4
Total Skips0
Total Code Submissions1
Total Times Completed0
Haskell Completions0
Total Stars0
% of votes with a positive feedback rating0% of 0
Total "Very Satisfied" Votes0
Total "Somewhat Satisfied" Votes0
Total "Not Satisfied" Votes0
Ad
Contributors
  • Paul Robertson Avatar
Ad