Stone Piles Discussions | Algorithms | HackerRank
  • + 0 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'