-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcoding669.py
27 lines (21 loc) · 1.12 KB
/
coding669.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
"""
Daily Coding Problem: Problem #669 [Hard]
Good morning! Here's your coding interview problem for today.
This problem was asked by Google.
The game of Nim is played as follows. Starting with three heaps, each containing a variable number of items, two players take turns removing one or more items from a single pile. The player who eventually is forced to take the last stone loses. For example, if the initial heap sizes are 3, 4, and 5, a game could be played as shown below:
A | B | C
-----------------
3 | 4 | 5
3 | 1 | 3
3 | 1 | 3
0 | 1 | 3
0 | 1 | 0
0 | 0 | 0
In other words, to start, the first player takes three items from pile B. The second player responds by removing two stones from pile C. The game continues in this way until player one takes last stone and loses.
Given a list of non-zero starting values [a, b, c], and assuming optimal play, determine whether the first player has a forced win.
"""
def doWin(piles):
return True if piles[0]^piles[1]^piles[2] !=0 else False
if __name__ == "__main__":
piles = [3,4,5]
print(doWin(piles))