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.
Grundy numbers for 0:0,1:0,2:0,3:1,4:0,5:2,6:3,7:4,8:0
Grundy number for n>=9 = n-4
Using Grundy Numbers following code:
def stonePiles(arr):
maps = {0:0,1:0,2:0,3:1,4:0,5:2,6:3,7:4,8:0}
res = 0
for ele in arr:
if ele<=8:
res^=maps[ele]
else:
res^=(ele-4)
if res == 0:
return 'BOB'
else:
return 'ALICE'
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Stone Piles
You are viewing a single comment's thread. Return to all comments →
Grundy numbers for 0:0,1:0,2:0,3:1,4:0,5:2,6:3,7:4,8:0 Grundy number for n>=9 = n-4
Using Grundy Numbers following code:
def stonePiles(arr): maps = {0:0,1:0,2:0,3:1,4:0,5:2,6:3,7:4,8:0} res = 0 for ele in arr: if ele<=8: res^=maps[ele] else: res^=(ele-4) if res == 0: return 'BOB' else: return 'ALICE'