Ctrl K

Stone Pile: Who Moves First

Easy
There is a pile of stones stones on the table. You and an opponent take turns, and you go first. On each turn a player must take 1, 2 or 3 stones from the pile. Whoever takes the last stone wins. Both players play perfectly. Return True if you can force a win, and False otherwise.
Example 1
stones=4 → False

Whether you take 1, 2 or 3 stones, your opponent takes the rest and wins.

Example 2
stones=7 → True

Take 3 stones: 4 are left, and now your opponent is the one in a losing spot.

Example 3
stones=2 → True

You take both stones at once.

Constraints
  • 1 ≤ stones ≤ 2³¹ - 1
Have you seen this problem in a real interview?
Solved by0
Tried by0
Submissions0
Acceptance—
Topics
Similar problemsDivisor Subtraction Duel EasyXOR Tile Duel HardTake From Any Pile MediumThe Vowel Cutting Game MediumA Toll of 115 Easy
loading Python…
Input
stones=4
Expected
False

Run checks the first 3 tests in your browser. Submit checks all 117 tests on the server, hidden ones included.