5 kyu

Extreme Hat Game

12 of 41porkfreezer

Description:

Do the simpler version first!

In this generalized version of the riddle, each 'player' has a hat and must guess what color it is. The players are lined up such that they can see the hats of everyone in front of them, but not their own hat or those of the players behind them. Each player must guess the color of their own hat, taking turns from back to front. In order to win, only one guess may be wrong.

The team will be told which colors of hats will be present (but not how many of each color) and given time to develop a strategy before they get their hats.

Your task is to create the team's strategy by writing a function that returns the guess for a player based on the information they have.

Inputs

  • a list of all colors of hat (possibly) present.

    Colors can be any Eq type; not just Strings.

  • a list of previous guesses, starting from the back (empty for the first player).

  • a list of the hats the player can see, starting with the one directly in front of them (empty for the last player).

Output

  • the guess, which should be one of the elements from the list of colors passed in

All inputs in the test cases will follow the rules of the riddle. Your solution should work for any number of colors, but the test cases will only go up to 5 colors and 100 players. Tests assume the first person to guess is wrong, since it is impossible to know what color hat they have.

Riddles

Stats:

CreatedJul 1, 2022
PublishedJul 3, 2022
Warriors Trained304
Total Skips54
Total Code Submissions201
Total Times Completed41
Haskell Completions12
Python Completions35
Total Stars11
% of votes with a positive feedback rating100% of 17
Total "Very Satisfied" Votes17
Total "Somewhat Satisfied" Votes0
Total "Not Satisfied" Votes0
Total Rank Assessments7
Average Assessed Rank
6 kyu
Highest Assessed Rank
5 kyu
Lowest Assessed Rank
7 kyu
Ad
Contributors
  • porkfreezer Avatar
  • Kacarott Avatar
Ad