Skip to content

Instantly share code, notes, and snippets.

@Judrummer
Last active September 22, 2018 05:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Judrummer/4c4a66df1e1844b9252e196d5d2feeff to your computer and use it in GitHub Desktop.
Save Judrummer/4c4a66df1e1844b9252e196d5d2feeff to your computer and use it in GitHub Desktop.
fun hangman(secretWord: String, letters: List<Char>): Boolean {
val remaingChars = secretWord.toCharArray().toMutableList()
var score = 7
var i = 0
while (remaingChars.size > 0 && i < letters.size && score > 0) {
if (!remaingChars.remove(letters[i])) score--
i++
}
return score > 0
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment