We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
Here is a great article that explains all the necessary theory: nim.pdf
I solved it using the game theory approach and found a much shorter solution (Python 2):
# precompute the Sprague-Grundy (SG) function for all 0 <= n <= 300g=[0,1,2]forninxrange(3,301):s=set()# hit one or two pinsforlin(1,2):# the group of n pins can be split into two # grops of i and n - l - i pinsforiinxrange((n-l)/2+1):s.add(g[i]^g[n-l-i])# compute mex (minimum excluded value)m=0whilemins:m+=1g.append(m)fortinxrange(int(raw_input().strip())):raw_input()ret=0# split the pins into groups and xor the SG valuesforpinraw_input().strip().split('X'):ret^=g[len(p)]print'WIN'ifretelse'LOSE'
Bowling Pins
You are viewing a single comment's thread. Return to all comments →
Excellent analysis!
Here is a great article that explains all the necessary theory: nim.pdf
I solved it using the game theory approach and found a much shorter solution (Python 2):