Skip to content

Instantly share code, notes, and snippets.

@svaza
Created January 25, 2022 02:53
Show Gist options
  • Select an option

  • Save svaza/d8a13910eb956a869ed4b328f28ec1c8 to your computer and use it in GitHub Desktop.

Select an option

Save svaza/d8a13910eb956a869ed4b328f28ec1c8 to your computer and use it in GitHub Desktop.
Divisor Game
// https://leetcode.com/problems/divisor-game/
public class Solution {
public enum Player { Alice = 1, Bob= 2 }
private const int X = 1;
public bool DivisorGame(int n) {
return WhoLooses(Player.Alice, n) != Player.Alice;
}
public Player WhoLooses(Player playerTurn, int n)
{
if(X > 0 && X < n)
{
if(playerTurn == Player.Alice)
{
return WhoLooses(Player.Bob, n - X);
}
else
{
return WhoLooses(Player.Alice, n - X);
}
}
else
{
return playerTurn;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment