DEV Community

Discussion on: Coding Interview: The Matchstick Game

Collapse
 
nestedsoftware profile image
Nested Software • Edited

Thanks for the comment @devkumi ! If the human player takes the first turn (and therefore can't win, no matter what), then that's all you need to do!

This version forces the computer to play first, which means the computer needs to know whether the human player has made a mistake or not. If the human player makes a mistake, then the remainder, r = (count - 1) mod 4 is used to compute the right move for the computer. I think in your case it would be 4 - (count mod 4) because you're going up from 0 to 21.