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.
Took a look at your python solution:
While it is fine and fast, it doesn't use recursion.
(I guess, all this problems in the 'Recursion' category are meant as an exercise how to make proficient use of recursion.)
Here is some recursive solution in python:
fromfunctoolsimportcache,reducefromoperatorimportxordefmex(seq):vals,ret=set(seq),0whileretinvals:ret+=1returnret@cachedefnim(run):reachable=[]reachable.extend(nim(i)^nim(run-i-1)foriinrange(0,(run+1)//2))reachable.extend(nim(i)^nim(run-i-2)foriinrange(0,run//2))returnmex(reachable)defisWinning(n,config):# Return WIN or LOSE depending on whether you will win runs=list(map(len,config.replace("X",' ').split()))return"WIN"ifreduce(xor,map(nim,runs))else"LOSE"
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Bowling Pins
You are viewing a single comment's thread. Return to all comments →
Took a look at your python solution:
While it is fine and fast, it doesn't use recursion.
(I guess, all this problems in the 'Recursion' category are meant as an exercise how to make proficient use of recursion.)
Here is some recursive solution in python: