Stone Removal Game - Problem
Alice and Bob's Stone Removal Challenge

Alice and Bob are engaged in a strategic stone removal game that tests their mathematical prowess! Here's how it works:

๐ŸŽฏ Game Rules:
โ€ข Alice always goes first and must remove exactly 10 stones on her opening move
โ€ข Each subsequent turn, players must remove exactly 1 fewer stone than their opponent's previous move
โ€ข The player who cannot make a valid move loses the game

๐Ÿ“Š Your Task:
Given a pile of n stones, determine if Alice has a winning strategy. Return true if Alice wins with optimal play, false otherwise.

๐Ÿ’ก Example: With 25 stones, Alice takes 10 (15 left), Bob takes 9 (6 left), Alice takes 8 but only 6 remain, so Alice takes 6 and wins!

Input & Output

example_1.py โ€” Basic Win Case
$ Input: n = 25
โ€บ Output: true
๐Ÿ’ก Note: Alice takes 10 (15 left), Bob takes 9 (6 left), Alice wants to take 8 but only 6 remain, so Alice takes all 6 and wins!
example_2.py โ€” Alice Loses
$ Input: n = 20
โ€บ Output: false
๐Ÿ’ก Note: Alice takes 10 (10 left), Bob takes 9 (1 left), Alice needs to take 8 but only 1 stone remains, so Alice cannot move and loses.
example_3.py โ€” Insufficient Stones
$ Input: n = 5
โ€บ Output: false
๐Ÿ’ก Note: Alice cannot even make her first move since she needs 10 stones but only 5 are available.

Constraints

  • 1 โ‰ค n โ‰ค 109
  • Alice must remove exactly 10 stones on her first turn
  • Each subsequent move must be exactly 1 fewer than the opponent's previous move
  • Players must make optimal moves

Visualization

Tap to expand
Stone Removal Pattern AnalysisSequence: 10 + 9 + 8 + 7 + 6 + 5 + 4 + 3 + 2 + 1 = 55Game Visualization10Alice9Bob8Alice7Bob6Alice5Bob...Key Insight: Triangular Number PatternComplete sequence sums to 55. Analyze remainder to determine winner!If n < 10: Alice loses immediately | If n โ‰ฅ 10: Simulate or use pattern analysis
Understanding the Visualization
1
Identify the Sequence
The game follows a decreasing sequence: 10, 9, 8, 7, 6, 5, 4, 3, 2, 1
2
Calculate Total
Sum of sequence 10+9+8+...+1 = 55 stones for a complete game
3
Analyze Remainder
If n > 55, analyze the remainder pattern to determine who gets stuck first
4
Determine Winner
Use the pattern to predict if Alice or Bob will be unable to make a move
Key Takeaway
๐ŸŽฏ Key Insight: The game follows a predictable mathematical pattern where we can determine the winner by analyzing the triangular number sequence and remainder stones.
Asked in
Google 15 Amazon 12 Microsoft 8 Meta 6
28.4K Views
Medium Frequency
~15 min Avg. Time
892 Likes
Ln 1, Col 1
Smart Actions
๐Ÿ’ก Explanation
AI Ready
๐Ÿ’ก Suggestion Tab to accept Esc to dismiss
// Output will appear here after running code
Code Editor Closed
Click the red button to reopen