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.
All pass with python. but need to add build_g_table() to main on the place before it call bendersPlay. Need the knowledge of grundy number and Game Theory
G_table=[]defbuild_g_table(n,paths):globalG_tablenext_table=[[]foriinrange(1+n)]G_table=[Noneforiinrange(1+n)]fora,binpaths:next_table[a].append(b)foriinrange(1,1+n):ifnotnext_table[i]:G_table[i]=0defcalculate_g_val(i,G_table):ifG_table[i]isnotNone:returnG_table[i]check_list=[1]*100fornext_innext_table[i]:ifG_table[next_]isNone:calculate_g_val(next_,G_table)temp=G_table[next_]check_list[temp]=0grundy_val=check_list.index(1)G_table[i]=grundy_valforiinrange(1,1+n):calculate_g_val(i,G_table)defbendersPlay(n,paths,query):# Write your code heretemp=0forqinquery:temp^=G_table[q]iftemp==0:return"Iroh"else:return"Bumi"
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Play on benders
You are viewing a single comment's thread. Return to all comments →
All pass with python. but need to add build_g_table() to main on the place before it call bendersPlay. Need the knowledge of grundy number and Game Theory