Created
October 31, 2017 05:05
-
-
Save maxwellmckinnon/14047caa8ab3f2b73c613fbc666e35de to your computer and use it in GitHub Desktop.
Solution to zero move nim
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/python3 | |
# Chris Grundy McKinnon method | |
import sys | |
from functools import reduce | |
g = int(input().strip()) | |
for a0 in range(g): | |
n = int(input().strip()) # num of heaps | |
p = [int(p_temp) for p_temp in input().strip().split(' ')] # pile counts | |
# your code goes here | |
# p is already the nimber of each pile. | |
# GRUNDULER | |
p = [(pt+1 if pt%2 == 1 else pt-1) for pt in p] | |
nimsum = reduce((lambda x,y: x^y), p) | |
won = False if nimsum == 0 else True | |
print('W') if won else print('L') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment