Skip to content

Instantly share code, notes, and snippets.

@ShadowfeindX
Created May 31, 2017 03:38
Show Gist options
  • Save ShadowfeindX/9a138e8d29789f905914f19e3a5dc868 to your computer and use it in GitHub Desktop.
Save ShadowfeindX/9a138e8d29789f905914f19e3a5dc868 to your computer and use it in GitHub Desktop.
Hang Yourself

A player wins a game of hangman if they can correctly guess all the letters in a word, or the word itself, before exceeding their allotted number of incorrect guesses. Generally this number is 7 (Head, neck, body, 2 arms, and 2 legs). If the player guesses the entire word they automatically receive the maximum possible score. If they guess the word incorrectly they immediately fail.

When playing multiple games or playing competitively, the games are scored. If the player guesses the same letter more than once, they lose points but they do not suffer an incorrect guess penalty. If the player gives up before guessing the word they also fail. The maximum score is 100, the minimum score is 0, and if the player fails to correctly guess the word, or all the letters, there score would be -10.

Given the word to be guessed as a string, the number of unique characters in the word and the players guesses in order as an array of strings, determine the players score and the total amount of incorrect characters they guessed before finding the correct word (or failing). The word will be all lowercase english characters.

Examples:

input -> 5; "water"; <"a","e","m","r","water","t"> output -> <90,1>

input -> 7; "backyard"; <"b","a","c","k","y","a","r","d"> output -> <90,0>

input -> 3; "dog"; <"a","e","i","o","u","h","g","b","c","d"> output -> <-10,7>

input -> 6; "sponge"; <"a","e","o","n","s","b"> output -> <-10,2>

Test Cases:

1-Immediately guess the word 2-Guess the word after correct characters 3-Guess the word after duplicate characters 4-Guess the word after incorrect characters 5-Guess incorrect characters after guessing the word 6-Guess every character of the word in order 7-Guess 4 incorrect characters 8-Guess 7 incorrect characters 9-Guess 6 incorrect characters and 5 duplicates 10-Guess 6 incorrect characters and then the word 11-Guess 7 incorrect characters and then the word 12-Guess duplicate incorrect characters 13-Guess an incorrect word 14-Guess all correct characters in order 15-Guess all correct characters in reverse order 16-Guess incorrect characters after correct characters are guess 17-Guess every letter of the alphabet in order 18-Guess capital letters 19-Guess numbers 20-Guess multiple characters at a time 21-Guess too few characters 22-Guess too few characters and incorrect characters 23-Guess too few characters and duplicate characters

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment