Problem Statement
The first pile initially contains size0 sticks and the second pile contains size1 sticks. Suppose both players play optimally. One of them has a winning strategy (no matter how his opponent plays he can always win) and he wants to win as fast as possible. The other player wants to lose as slowly as possible.
Return a
Definition
- Class:
- PowerGame
- Method:
- winner
- Parameters:
- int, int
- Returns:
- String
- Method signature:
- String winner(int size0, int size1)
- (be sure your method is public)
Constraints
- size0 and size1 will each be between 1 and 10000, inclusive.
Examples
10000
10000
Returns: "Alan will win after 1 moves"
4
9
Returns: "Alan will win after 1 moves"
A player can take 1, 4, 9, 16, 25, ... sticks. Alan can make all the piles empty in his first move, leaving Bob with no valid moves. He will win the game after 1 turn.
4
3
Returns: "Alan will win after 1 moves"
Alan can remove all the sticks from the first pile in his first turn, leaving Bob with no valid moves.
2
3
Returns: "Bob will win after 2 moves"
The only possible move for both players is removing one stick during each turn.
7
13
Returns: "Bob will win after 4 moves"
2136
1244
Returns: "Alan will win after 7 moves"
3
5
Returns: "Bob will win after 2 moves"
1
1
Returns: "Alan will win after 1 moves"
1
10000
Returns: "Alan will win after 1 moves"
28
17
Returns: "Alan will win after 7 moves"
884
5521
Returns: "Alan will win after 15 moves"
9113
2842
Returns: "Alan will win after 23 moves"
6673
8111
Returns: "Alan will win after 25 moves"
24
9019
Returns: "Alan will win after 5 moves"
502
213
Returns: "Alan will win after 9 moves"
9999
9999
Returns: "Alan will win after 31 moves"
9112
9112
Returns: "Alan will win after 21 moves"
7172
42
Returns: "Alan will win after 9 moves"
8806
9753
Returns: "Alan will win after 31 moves"
2224
5813
Returns: "Alan will win after 5 moves"
8444
8444
Returns: "Alan will win after 35 moves"
9013
9017
Returns: "Alan will win after 15 moves"
46
47
Returns: "Alan will win after 5 moves"
883
7721
Returns: "Alan will win after 17 moves"
2
2
Returns: "Bob will win after 2 moves"
3
3
Returns: "Alan will win after 3 moves"
4
4
Returns: "Alan will win after 1 moves"
5
5
Returns: "Bob will win after 2 moves"
99
99
Returns: "Alan will win after 13 moves"
4234
3852
Returns: "Alan will win after 17 moves"
515
61
Returns: "Alan will win after 7 moves"
8
8887
Returns: "Alan will win after 5 moves"
6642
6642
Returns: "Bob will win after 40 moves"
4009
4009
Returns: "Alan will win after 29 moves"
4567
8671
Returns: "Alan will win after 9 moves"
8999
9999
Returns: "Alan will win after 19 moves"
4563
2314
Returns: "Alan will win after 5 moves"
3454
4456
Returns: "Alan will win after 31 moves"
9563
8914
Returns: "Alan will win after 25 moves"
9000
8999
Returns: "Alan will win after 19 moves"
9876
1234
Returns: "Alan will win after 15 moves"
9456
8754
Returns: "Alan will win after 21 moves"
10
10
Returns: "Bob will win after 4 moves"