Statistics

Problem Statement for "TakeStones"

Problem Statement

You are playing a game where you and another player alternately take turns taking stones from a single central pile of stones.

Initially, the pile contains stonePile stones.

You are the first player to make a move. On each turn, the active player must take at least one stone and at most maxStones stones from the central pile.

Assume that both you and the other player play the game optimally. Return "WIN" if you will win the game or "LOSE" if you will lose the game.

Definition

Class:
TakeStones
Method:
result
Parameters:
int, int
Returns:
String
Method signature:
String result(int stonePile, int maxStones)
(be sure your method is public)

Notes

  • The return value is case-sensitive: the "WIN" and "LOSE" must be in uppercase.

Constraints

  • stonePile will be between 1 and 100, inclusive.
  • maxStones will be between 1 and 100, inclusive.

Examples

  1. 5

    3

    Returns: "WIN"

    The central pile starts with 5 stones. During each turn the active player may remove between 1 and 3 stones, inclusive. You can win the game regardless of how well your opponent plays. If you start by taking one stone, the other player is left with four stones in the central pile. Regardless of how many they take (1, 2, or 3), in your second turn you can always take everything they left in the central pile and win.

  2. 4

    3

    Returns: "LOSE"

    Here, it's the opposite situation. Regardless how many you take, the opponent will be able to take the rest and win.

  3. 7

    5

    Returns: "WIN"

  4. 30

    8

    Returns: "WIN"

  5. 100

    99

    Returns: "LOSE"

  6. 7

    47

    Returns: "WIN"

    Your winning strategy in this game is simple: on your first turn, take all seven stones and win.

  7. 100

    11

    Returns: "WIN"

  8. 4

    1

    Returns: "LOSE"

  9. 8

    5

    Returns: "WIN"

  10. 6

    3

    Returns: "WIN"

  11. 8

    1

    Returns: "LOSE"

  12. 81

    8

    Returns: "LOSE"

  13. 8

    3

    Returns: "LOSE"

  14. 12

    3

    Returns: "LOSE"

  15. 10

    4

    Returns: "LOSE"

  16. 1

    5

    Returns: "WIN"

  17. 5

    2

    Returns: "WIN"

  18. 50

    7

    Returns: "WIN"

  19. 3

    1

    Returns: "WIN"

  20. 100

    50

    Returns: "WIN"

  21. 10

    3

    Returns: "WIN"

  22. 22

    3

    Returns: "WIN"

  23. 50

    9

    Returns: "LOSE"


This problem statement is the exclusive and proprietary property of TopCoder, Inc. Any unauthorized use or reproduction of this information without the prior written consent of TopCoder, Inc. is strictly prohibited. (c)2024, TopCoder, Inc. All rights reserved.
This problem was used for: