# Rock Paper Scissors

Let's play! You have to return which player won! In case of a draw return `Draw!`.

Examples:

![rockpaperscissors](http://i.imgur.com/aimOQVX.png)

Source: codewars | Difficulty: EASY
Tags: Fundamentals

Starter code: def rps(p1, p2):
	

Solutions:
def rps(p1, p2):
	beats = {'rock': 'scissors', 'scissors': 'paper', 'paper': 'rock'}
	if beats[p1] == p2:
		return 'Player 1 won!'
	if beats[p2] == p1:
		return 'Player 2 won!'
	return 'Draw!'


def rps(p1, p2):
	hand = {'rock': 0, 'paper': 1, 'scissors': 2}
	results = ['Draw!', 'Player 1 won!', 'Player 2 won!']
	return results[hand[p1] - hand[p2]]


def rps(p1, p2):
	if p1 == p2:
		return 'Draw!'
	elif p1 == 'rock' and p2 == 'scissors' or (p1 == 'scissors' and p2 == 'paper') or (p1 == 'paper' and p2 == 'rock'):
		return 'Player 1 won!'
	else:
		return 'Player 2 won!'


def rps(p1, p2):
	winner = {'scissors': 'paper', 'paper': 'rock', 'rock': 'scissors'}
	if p1 == p2:
		return 'Draw!'
	elif winner[p1] == p2:
		return 'Player 1 won!'
	elif winner[p2] == p1:
		return 'Player 2 won!'


RPS = {('rock', 'rock'): 'Draw!', ('rock', 'paper'): 'Player 2 won!', ('rock', 'scissors'): 'Player 1 won!', ('paper', 'rock'): 'Player 1 won!', ('paper', 'paper'): 'Draw!', ('paper', 'scissors'): 'Player 2 won!', ('scissors', 'rock'): 'Player 2 won!', ('scissors', 'paper'): 'Player 1 won!', ('scissors', 'scissors'): 'Draw!'}

def rps(p1, p2):
	return RPS[p1, p2]


rps = lambda a, b: ['Draw!', 'Player 1 won!', 'Player 2 won!'][('srp'.index(a[0]) - 'srp'.index(b[0])) % 3]


def rps(p1, p2):
	d1 = [('paper', 'rock'), ('rock', 'scissors'), ('scissors', 'paper')]
	return 'Draw!' if p1 == p2 else 'Player {} won!'.format(1 if (p1, p2) in d1 else 2)


def rps(p1, p2):
	if p1 == p2:
		return 'Draw!'
	rock_sciss = p1 == 'rock' and p2 == 'scissors'
	paper_rock = p1 == 'paper' and p2 == 'rock'
	sciss_paper = p1 == 'scissors' and p2 == 'paper'
	if rock_sciss or paper_rock or sciss_paper:
		return 'Player 1 won!'
	else:
		return 'Player 2 won!'


def rps(p1, p2):
	if p1 == p2:
		return 'Draw!'
	return 'Player 1 won!' if p1[0] + p2[0] == 'sp' or p1[0] + p2[0] == 'rs' or p1[0] + p2[0] == 'pr' else 'Player 2 won!'


def rps(p1, p2):
	options = ['rock', 'paper', 'scissors']
	outcomes = ['Draw!', 'Player 1 won!', 'Player 2 won!']
	return outcomes[options.index(p1) - options.index(p2)]


def rps(p1, p2):
	return f"Player {1 + (p1[0] + p2[0] in 'psrp')} won!" if p1 != p2 else 'Draw!'


def rps(p1, p2):
	if p1 == p2:
		return 'Draw!'
	favourable_matchups = {'rock': 'scissors', 'scissors': 'paper', 'paper': 'rock'}
	return 'Player 1 won!' if favourable_matchups[p1] == p2 else 'Player 2 won!'


rps = lambda p1, p2, l=['rock', 'paper', 'scissors']: 'Draw!' if p1 == p2 else 'Player {} won!'.format(1 + (l.index(p2) - l.index(p1) in [1, -2]))


def rps(p1, p2):
	return p1 == p2 and 'Draw!' or f"Player {(p2[0] + p1[0] in 'rspr') + 1} won!"


def rps(p1, p2):
	nums = ['rock', 'scissors', 'paper']
	p1 = nums.index(p1)
	p2 = nums.index(p2)
	if p1 == p2:
		return 'Draw!'
	elif (p2 - p1) % 3 == 1:
		return 'Player 1 won!'
	else:
		return 'Player 2 won!'


BEATS = {'rock': 'scissors', 'scissors': 'paper', 'paper': 'rock'}

def rps(p1, p2):
	return 'Draw!' if p1 == p2 else __winner(p1, p2)

def __winner(p1, p2):
	return 'Player 1 won!' if BEATS[p1] == p2 else 'Player 2 won!'


rps = lambda p1, p2: (lambda a: 'Draw!' if a == 0 else 'Player 1 won!' if a % 3 == 2 else 'Player 2 won!')(['paper', 'rock', 'scissors'].index(p1) - ['paper', 'rock', 'scissors'].index(p2))


def rps(p1, p2):
	if p1 == p2:
		return 'Draw!'
	elif (p1, p2) in [('rock', 'scissors'), ('scissors', 'paper'), ('paper', 'rock')]:
		return 'Player 1 won!'
	else:
		return 'Player 2 won!'


def rps(p1, p2):
	d = dict(rock=0, paper=1, scissors=2)
	return ('Draw!', 'Player 1 won!', 'Player 2 won!')[(d[p1] - d[p2]) % 3]


def rps(*args):
	return 'Draw!' if len(set(args)) == 1 else 'Player {} won!'.format(1 + args.index('rock' if set(args) == {'rock', 'scissors'} else max(args, key=len)))


def rps(p1, p2):
	if p1 == p2:
		return 'Draw!'
	game_map = {('rock', 'scissors'): 'rock', ('scissors', 'paper'): 'scissors', ('paper', 'rock'): 'paper'}
	winner = game_map.get((p1, p2), False) or game_map.get((p2, p1), False)
	return 'Player 1 won!' if p1 == winner else 'Player 2 won!'


def rps(p1, p2):
	return 'Draw!' if p1 == p2 else 'Player {} won!'.format(-~(p2[0] + p1[0] in 'rspr'))


def rps(p1, p2):
	rule = {'scissors': 'paper', 'paper': 'rock', 'rock': 'scissors'}
	return ['Player %d won!' % [2, 1][rule[p1] == p2], 'Draw!'][p1 == p2]


def rps(p1, p2):
	p1c = ['p1rp2s', 'p1sp2p', 'p1pp2r']
	p2c = ['p1sp2r', 'p1pp2s', 'p1rp2p']
	p1w = 'Player 1 won!'
	p2w = 'Player 2 won!'
	p3w = 'Draw!'
	i = 'p1{}p2{}'.format(p1[0], p2[0])
	return p1w if i in p1c else p2w if i in p2c else p3w


def rps(p1, p2):
	r = 'rock'
	p = 'paper'
	s = 'scissors'
	p1w = 'Player 1 won!'
	p2w = 'Player 2 won!'
	if p1 == r and p2 == s:
		return p1w
	if p1 == r and p2 == p:
		return p2w
	if p1 == p and p2 == s:
		return p2w
	if p1 == p and p2 == r:
		return p1w
	if p1 == s and p2 == r:
		return p2w
	if p1 == s and p2 == p:
		return p1w
	else:
		return 'Draw!'


def rps(p1: str, p2: str) -> str:
	score_rules = {'scissors': {'paper': True, 'rock': False}, 'paper': {'scissors': False, 'rock': True}, 'rock': {'scissors': True, 'paper': False}}
	if p1 == p2:
		return 'Draw!'
	elif score_rules.get(p1).get(p2):
		return 'Player 1 won!'
	else:
		return 'Player 2 won!'


def rps(p1, p2):
	m = ['rock', 'paper', 'scissors']
	return ['Draw!', 'Player 1 won!', 'Player 2 won!'][m.index(p1) - m.index(p2)]


def rps(p1, p2):
	res = ('rsp'.find(p2[0]) - 'rsp'.find(p1[0])) % 3
	return f'Player {res} won!' if res else 'Draw!'


def rps(p1, p2):
	game = ('rock', 'paper', 'scissors')
	if p1 == 'scissors' and p2 == 'paper':
		return 'Player 1 won!'
	elif p1 == 'rock' and p2 == 'scissors':
		return 'Player 1 won!'
	elif p1 == 'paper' and p2 == 'rock':
		return 'Player 1 won!'
	if p1 == 'scissors' and p2 == 'rock':
		return 'Player 2 won!'
	elif p1 == 'paper' and p2 == 'scissors':
		return 'Player 2 won!'
	elif p1 == 'rock' and p2 == 'paper':
		return 'Player 2 won!'
	elif p1 == 'rock' and p2 == 'rock':
		return 'Draw!'
	elif p1 == 'scissors' and p2 == 'scissors':
		return 'Draw!'
	elif p1 == 'paper' and p2 == 'paper':
		return 'Draw!'


def rps(p1, p2):
	values = {'rock': 0, 'scissors': 1, 'paper': 2}
	if (values[p1] - values[p2]) % 3 == 0:
		return 'Draw!'
	elif (values[p1] - values[p2]) % 3 == 2:
		return 'Player 1 won!'
	else:
		return 'Player 2 won!'


def rps(*players):
	result = 'Draw!'
	if players[0] != players[1]:
		if 'rock' in players and (not 'paper' in players):
			winner = players.index('rock') + 1
		elif 'paper' in players and (not 'scissors' in players):
			winner = players.index('paper') + 1
		elif 'scissors' in players and (not 'rock' in players):
			winner = players.index('scissors') + 1
		result = 'Player %s won!' % winner
	return result


def rps(p1, p2):
	rock = 'rock'
	paper = 'paper'
	scissors = 'scissors'
	p1won = 'Player 1 won!'
	p2won = 'Player 2 won!'
	draw = 'Draw!'
	solutions = {rock: {rock: draw, paper: p2won, scissors: p1won}, paper: {rock: p1won, paper: draw, scissors: p2won}, scissors: {rock: p2won, paper: p1won, scissors: draw}}
	return solutions[p1][p2]


P1_WINS = {'scissorspaper', 'paperrock', 'rockscissors'}

def rps(p1, p2):
	if p1 == p2:
		return 'Draw!'
	return 'Player {} won!'.format(1 if p1 + p2 in P1_WINS else 2)


def rps(p1, p2):
	v = {'p': 1, 'r': 0, 's': -1}
	return 'Draw!' if p1 == p2 else 'Player 1 won!' if v[p1[0]] - v[p2[0]] in [1, -2] else 'Player 2 won!'


def rps(p1, p2):
	if p1 == p2:
		return 'Draw!'
	dic = {'rs': 1, 'sp': 1, 'ps': 2, 'sr': 2, 'pr': 1, 'rp': 2}
	return f'Player {dic[p1[0] + p2[0]]} won!'


def rps(p1, p2):
	x = ('rock', 'scissors', 'paper')
	y = ('rock', 'scissors', 'paper')
	if p1 == p2:
		return 'Draw!'
	elif p1 == x[0] and p2 == y[1]:
		return 'Player 1 won!'
	elif p1 == x[1] and p2 == y[2]:
		return 'Player 1 won!'
	elif p1 == x[2] and p2 == y[0]:
		return 'Player 1 won!'
	else:
		return 'Player 2 won!'


winner = lambda a, b: {'scissors': 'paper', 'rock': 'scissors', 'paper': 'rock'}[a] == b

def rps(p1, p2):
	return 'Draw!' if p1 == p2 else 'Player 1 won!' if winner(p1, p2) else 'Player 2 won!'


def rps(p1, p2):
	if p1 == p2:
		return 'Draw!'
	elif p1 == 'scissors' and p2 == 'paper':
		return 'Player 1 won!'
	elif p1 == 'rock' and p2 == 'scissors':
		return 'Player 1 won!'
	elif p1 == 'paper' and p2 == 'rock':
		return 'Player 1 won!'
	else:
		return 'Player 2 won!'
r1 = 'rock'
r2 = 'scissors'
print(rps(r1, r2))


def rps(a: str, b: str):
	c: str = 'Player 1 won!'
	d: str = 'Player 2 won!'
	e: str = 'Draw!'
	if a == 'rock' and b == 'scissors':
		return c
	if a == 'scissors' and b == 'paper':
		return c
	if a == 'paper' and b == 'rock':
		return c
	if a == 'rock' and b == 'paper':
		return d
	if a == 'scissors' and b == 'rock':
		return d
	if a == 'paper' and b == 'scissors':
		return d
	else:
		return e


def rps(p1, p2):
	print(p1, p2)
	if p1 == p2:
		return 'Draw!'
	if p1 == 'scissors' and p2 != 'rock':
		return 'Player 1 won!'
	if p1 == 'scissors' and p2 == 'rock':
		return 'Player 2 won!'
	if p2 == 'scissors' and p1 != 'rock':
		return 'Player 2 won!'
	if p2 == 'scissors' and p1 == 'rock':
		return 'Player 1 won!'
	if p1 == 'paper' and p2 != 'scissors':
		return 'Player 1 won!'
	if p1 == 'paper' and p2 == 'scissors':
		return 'player 2 won!'
	if p2 == 'paper' and p1 != 'scissors':
		return 'Player 2 won!'
	if p2 == 'paper' and p1 == 'scissors':
		return 'player 1 won!'


def rps(p1, p2):
	rules = {'rock': 'scissors', 'scissors': 'paper', 'paper': 'rock'}
	if rules.get(p1) == p2:
		a = 1
	elif rules.get(p2) == p1:
		a = 2
	else:
		return 'Draw!'
	return f'Player {a} won!'


def rps(p1, p2):
	game = ['rock', 'paper', 'scissors']
	(s1, s2) = (game.index(p1), game.index(p2))
	if s1 == s2:
		return 'Draw!'
	if s1 == 0 and s2 == 2 or (s1 == 2 and s2 == 1) or (s1 == 1 and s2 == 0):
		return 'Player 1 won!'
	return 'Player 2 won!'


def rps(p1, p2):
	result = [p1, p2]
	if result[0] == 'rock':
		if result[1] == 'paper':
			return 'Player 2 won!'
		if result[1] == 'rock':
			return 'Draw!'
		if result[1] == 'scissors':
			return 'Player 1 won!'
	elif result[0] == 'paper':
		if result[1] == 'rock':
			return 'Player 1 won!'
		if result[1] == 'paper':
			return 'Draw!'
		if result[1] == 'scissors':
			return 'Player 2 won!'
	elif result[0] == 'scissors':
		if result[1] == 'scissors':
			return 'Draw!'
		if result[1] == 'paper':
			return 'Player 1 won!'
		if result[1] == 'rock':
			return 'Player 2 won!'


def rps(p1, p2):
	if p1[0] == 'r' and p2[0] == 's':
		soluzione = 'Player 1 won!'
	elif p1[0] == 'p' and p2[0] == 's':
		soluzione = 'Player 2 won!'
	elif p1[0] == 'r' and p2[0] == 'p':
		soluzione = 'Player 2 won!'
	elif p1[0] == 'p' and p2[0] == 'r':
		soluzione = 'Player 1 won!'
	elif p1[0] == 's' and p2[0] == 'r':
		soluzione = 'Player 2 won!'
	elif p1[0] == 's' and p2[0] == 'p':
		soluzione = 'Player 1 won!'
	else:
		soluzione = 'Draw!'
	return soluzione


def rps(p1, p2):
	return {p1 == 'rock' and p2 == 'scissors' or (p1 == 'paper' and p2 == 'rock') or (p1 == 'scissors' and p2 == 'paper'): 'Player 1 won!', p1 == p2: 'Draw!'}.get(1, 'Player 2 won!')


def rps(p1, p2):
	sc = 'scissors'
	pp = 'paper'
	rc = 'rock'
	inpt = [p1, p2]
	if inpt == [sc, pp] or inpt == [rc, sc] or inpt == [pp, rc]:
		return 'Player 1 won!'
	if inpt == [pp, sc] or inpt == [sc, rc] or inpt == [rc, pp]:
		return 'Player 2 won!'
	else:
		return 'Draw!'


def rps(p1, p2):
	return {'rockscissors': 'Player 1 won!', 'scissorspaper': 'Player 1 won!', 'paperrock': 'Player 1 won!', 'scissorsrock': 'Player 2 won!', 'paperscissors': 'Player 2 won!', 'rockpaper': 'Player 2 won!', 'rockrock': 'Draw!', 'scissorsscissors': 'Draw!', 'paperpaper': 'Draw!'}.get(p1 + p2)


def wins(hand1, hand2):
	if hand1 == 'scissors' and hand2 == 'paper':
		return '1'
	elif hand1 == 'paper' and hand2 == 'rock':
		return '1'
	elif hand1 == 'rock' and hand2 == 'scissors':
		return '1'
	else:
		return '2'

def rps(p1, p2):
	if p1 == p2:
		return 'Draw!'
	else:
		return 'Player ' + wins(p1, p2) + ' won!'


DRAW = 'Draw!'
P1_WIN = 'Player 1 won!'
P2_WIN = 'Player 2 won!'
gamestate = {'rock': {'rock': DRAW, 'paper': P2_WIN, 'scissors': P1_WIN}, 'paper': {'rock': P1_WIN, 'paper': DRAW, 'scissors': P2_WIN}, 'scissors': {'rock': P2_WIN, 'paper': P1_WIN, 'scissors': DRAW}}

def rps(p1, p2):
	return gamestate[p1][p2]

def rps2(p1, p2):
	if p1 == 'scissors' and p2 == 'paper':
		return 'Player 1 won!'
	elif p1 == 'scissors' and p2 == 'rock':
		return 'Player 2 won!'
	elif p1 == p2:
		return 'Draw!'
	elif p1 == 'paper' and p2 == 'scissors':
		return 'Player 2 won!'
	elif p1 == 'paper' and p2 == 'rock':
		return 'Player 1 won!'
	elif p1 == 'rock' and p2 == 'scissors':
		return 'Player 1 won!'
	elif p1 == 'rock' and p2 == 'paper':
		return 'Player 2 won!'


def rps(p1, p2):
	d = {('rock', 'scissors'): 'Player 1 won!', ('paper', 'scissors'): 'Player 2 won!', ('paper', 'rock'): 'Player 1 won!', ('scissors', 'rock'): 'Player 2 won!', ('scissors', 'paper'): 'Player 1 won!', ('rock', 'paper'): 'Player 2 won!', ('paper', 'paper'): 'Draw!', ('rock', 'rock'): 'Draw!', ('scissors', 'scissors'): 'Draw!'}
	if (p1, p2) in d:
		return d[p1, p2]