Tap here to switch tabs
Problem
Submissions

Problem: Nim Game

Nim Game gives you a heap of stones and alternating turns. Return whether you can remove the last stone when each turn allows one to three stones and both play optimally.

Statement

You and a friend are playing a game called the Nim Game with a heap of stones. The rules are as follows:

  • There is a single heap containing n stones.

  • You and your friend take alternating turns, with you going first.

  • On each turn, the current player must remove between 11 and 33 stones (inclusive) from the heap.

  • The player who removes the last stone wins the game.

Given n, the number of stones in the heap, return TRUE if you can win the game assuming both players play optimally, otherwise return FALSE.

Constraints:

  • 1≤1 \leq n ≤231−1\leq 2^{31} - 1

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Nim Game

Nim Game gives you a heap of stones and alternating turns. Return whether you can remove the last stone when each turn allows one to three stones and both play optimally.

Statement

You and a friend are playing a game called the Nim Game with a heap of stones. The rules are as follows:

  • There is a single heap containing n stones.

  • You and your friend take alternating turns, with you going first.

  • On each turn, the current player must remove between 11 and 33 stones (inclusive) from the heap.

  • The player who removes the last stone wins the game.

Given n, the number of stones in the heap, return TRUE if you can win the game assuming both players play optimally, otherwise return FALSE.

Constraints:

  • 1≤1 \leq n ≤231−1\leq 2^{31} - 1