log in
About and Contact
© 2020 DOUBTCOOL
The logic is behind this game is simple
--> two players are playing a game with an array of elements(numbers)
alternate chances are given to each players.
when player1 is playing the chance , he have to search for the highest element in the array , eliminate it as well as elements that
are right to it..
for example:-
array[5] = { 10 , 12, 5 , 5, 6, 20 , 14, };
player1( andy) searches for highest number in it... i.e, 20
and player has to eliminate the number and as well as number after it.
hence the array is updated to
array={ 10 , 12, 5 , 5, 6 };
then player2(bob) will get the chances to play with updated array...
and the game continues..
the game ends when any player not finding any element in array to eliminate , that player loses..
check out python code for this...
a=[10 , 12, 5 , 5, 6, 20 , 14] chc = 0 # chances count while(len(a)!=0): chc= chc+1 m=max(a) # it returns maximum number present in array mi=a.index(m) # finds index/position of maximum number del a[mi:] # deletes all number/elements after the maximum number , the array is updated if(chc%2==0): print("player2(bob) wins") else: print("player1(andy) wins")
a=[10 , 12, 5 , 5, 6, 20 , 14] chc = 0 # chances count while(len(a)!=0): chc= chc+1 m=max(a) # it returns maximum number present in array mi=a.index(m) # finds index/position of maximum number del a[mi:] # deletes all number/elements after the maximum number , the array is updated if(chc%2==0): print("BOB") else: print("ANDY")