a-coin-game

Rahul and Rashi are bored with playing the game of Nim, particularly after Rahul gained a thorough understanding of game theory, and would always win.

Now, they are going to play on a variation. 
There are only 2 piles of coins. Each player can make the following move:
Pick K ( ≥ 1) coins from pile 1.
Pick K ( ≥ 1) coins from pile 2.
Pick K ( ≥ 1) coins from pile 1 as well as pile 2.

As with the older version, the person unable to make a move shall lose. Can you help analyse this game for the novice, Rashi.

Input Format:

The first line contains an integer T, denoting the number of test cases to follow.
The next T lines each contain two integers N1 and N2, separated by a single space, denoting sizes of first pile and second pile respectively. 

Output Format:

The output file should contain exactly T lines.
Output Play, if Rashi would win as the first player and Don't Play, if she shall lose.

Constraints:

1 ≤ T ≤ 10^5
0 ≤ N1, N2 ≤ 10^6

SAMPLE INPUT
3
1 1
0 2
1 2

SAMPLE OUTPUT
Play
Play
Don't Play

Source: hackerearth | Difficulty: MEDIUM
Tags: Game theory

Mathematics


Solutions:
a = {}

def winOrLose(x, y):
	if (x > y):
		return winOrLose(y, x)
	if (a[x] == y):
		return False
	return True

def compute():
	a[0] = 0
	d = 1
	for i in range(1000007):
		if(i in a):
			continue
		else:
			a[i] = i + d
			a[i + d] = i
			d += 1
compute()
numOfInput = int(input())

for x in range(numOfInput):
	vals = list(map(int, input().split(" ")))  
	if(winOrLose(vals[0],vals[1])):
		print("Play")
	else:
		print("Don't Play")


T = int(input())
X = [None for i in range(2*(10**6) )]
j = 1
for i in range(1, 10**6+4):
	if X[i] is None:
		X[i] = i + j
		X[i+j] = i
		j += 1
#print X[:10]		
for i in range(T):
	N1, N2 = [int(i) for i in input().split()]
	if N1 > N2:
		temp = N2
		N2= N1
		N1 = temp
	if N2 == 0:
		print("Don't Play")
	elif N1 != N2 and N1 != 0 and X[N1] ==N2:
		print("Don't Play")
	else:
		print("Play")
	
	


l = [0]*1000000
d=1
for i in range(1,1000000):
	if l[i] == 0:
		l[i] = i+d
		if (i+d)<1000000:
			l[i+d] = i
		d+=1
'''
for i,j in enumerate(l):
	if j!=0:
		print i,j '''
def winOrLoose(a,b):
	if l[a] == b:
		return False
	return True

for tc in range(eval(input())):
	n1,n2= list(map(int,input().split()))
	if winOrLoose(n1,n2):
		print('Play')
	else:
		print("Don't Play")


a = {}

def winOrLose(x, y):
	if (x > y):
		return winOrLose(y, x)
	if (a[x] == y):
		return False
	return True

def compute():
	a[0] = 0
	d = 1
	for i in range(1000007):
		if(i in a):
			continue
		else:
			a[i] = i + d
			a[i + d] = i
			d += 1
compute()
numOfInput = int(input())

for x in range(numOfInput):
	vals = list(map(int, input().split(" ")))  
	if(winOrLose(vals[0],vals[1])):
		print("Play")
	else:
		print("Don't Play")


maxn = 10**6
cold_pos = {}

def gen_cold():
	d = 0
	i = 0
	while (i < maxn):
		if not (i in cold_pos):
			cold_pos[i] = i + d
			cold_pos[i + d] = i
			d += 1
		i += 1

if __name__ == "__main__":
	gen_cold()
	t = int(input())
	for i in range(t):
		n = list(map(int, input().split(" ")))
		if n[1] == cold_pos[n[0]]:
			print("Don't Play")
		else:
			print("Play")