Steve and Josh are bored and want to play something. They don't want to think too much, so they come up with a really simple game. Write a function called winner and figure out who is going to win.

They are dealt the same number of cards. They both flip the card on the top of their deck. Whoever has a card with higher value wins the round and gets one point (if the cards are of the same value, neither of them gets a point). After this, the two cards are discarded and they flip another card from the top of their deck. They do this until they have no cards left.

`deckSteve` and `deckJosh` are arrays representing their decks. They are filled with *cards*, represented by a single character. The card rank is as follows (from lowest to highest):
```
'2','3','4','5','6','7','8','9','T','J','Q','K','A'
```

Every card may appear in the deck more than once. Figure out who is going to win and return who wins and with what score:
* `"Steve wins x to y"` if Steve wins; where `x` is Steve's score, `y` is Josh's score;
* `"Josh wins x to y"` if Josh wins; where `x` is Josh's score, `y` is Steve's score;
* `"Tie"` if the score is tied at the end of the game.


## Example

* Steve is dealt: `['A','7','8']`
* Josh is dealt: `['K','5','9']`

1. In the first round, ace beats king and Steve gets one point.
2. In the second round, 7 beats 5 and Steve gets his second point.
3. In the third round, 9 beats 8 and Josh gets one point.

So you should return: `"Steve wins 2 to 1"`

Source: codewars | Difficulty: EASY
Tags: Data structures

Game theory

Starter code: def winner(deck_steve, deck_josh):
	

Solutions:
def winner(deck_Steve, deck_Josh):
	deck = ['2', '3', '4', '5', '6', '7', '8', '9', 'T', 'J', 'Q', 'K', 'A']
	Steve = 0
	Josh = 0
	for i in range(len(deck_Steve)):
		if deck.index(deck_Steve[i]) > deck.index(deck_Josh[i]):
			Steve += 1
		elif deck.index(deck_Steve[i]) < deck.index(deck_Josh[i]):
			Josh += 1
		else:
			continue
	if Steve > Josh:
		return 'Steve wins ' + str(Steve) + ' to ' + str(Josh)
	elif Josh > Steve:
		return 'Josh wins ' + str(Josh) + ' to ' + str(Steve)
	else:
		return 'Tie'


ranks = '23456789TJQKA'

def winner(deck_steve, deck_josh):
	steve_points = sum([1 for i in range(len(deck_steve)) if ranks.index(deck_steve[i]) > ranks.index(deck_josh[i])])
	josh_points = sum([1 for i in range(len(deck_josh)) if ranks.index(deck_steve[i]) < ranks.index(deck_josh[i])])
	if steve_points > josh_points:
		return 'Steve wins %d to %d' % (steve_points, josh_points)
	elif josh_points > steve_points:
		return 'Josh wins %d to %d' % (josh_points, steve_points)
	else:
		return 'Tie'


CARDS = ['2', '3', '4', '5', '6', '7', '8', '9', 'T', 'J', 'Q', 'K', 'A']
CARDS_VAL = {elt: i for (i, elt) in enumerate(CARDS)}

def winner(deck_steve, deck_josh):
	resultLst = [CARDS_VAL[c1] > CARDS_VAL[c2] for (c1, c2) in zip(deck_steve, deck_josh) if CARDS_VAL[c1] != CARDS_VAL[c2]]
	(result, l) = (sum(resultLst), len(resultLst))
	return ['Josh wins {} to {}'.format(l - result, result), 'Steve wins {} to {}'.format(result, l - result), 'Tie'][(result >= l / 2.0) + (result == l / 2.0)]


def winner(deck_s, deck_j):
	points = {True: ['Steve', 0], False: ['Josh', 0]}
	chek_dek = ['2', '3', '4', '5', '6', '7', '8', '9', 'T', 'J', 'Q', 'K', 'A']
	for (s, j) in zip(deck_s, deck_j):
		point = chek_dek.index(s) - chek_dek.index(j)
		if not point:
			continue
		points[point > 0][-1] += 1
	winer = points[points[1][-1] > points[0][-1]][0]
	if points[1][-1] == points[0][-1]:
		return 'Tie'
	return f'{winer} wins {points[winer == points[1][0]][-1]} to {points[winer == points[0][0]][-1]}'


b = '23456789TJQKA'

def winner(S, J):
	w1 = sum((b.index(s) > b.index(j) for (s, j) in zip(S, J)))
	w2 = sum((b.index(s) < b.index(j) for (s, j) in zip(S, J)))
	if w1 == w2:
		return 'Tie'
	if w1 > w2:
		return f'Steve wins {w1} to {w2}'
	return f'Josh wins {w2} to {w1}'


def winner(deck_steve, deck_josh):
	bigOrSmall = ['2', '3', '4', '5', '6', '7', '8', '9', 'T', 'J', 'Q', 'K', 'A']
	m = '{} wins {} to {}'
	winSteve = 0
	winJosh = 0
	for i in range(len(deck_steve)):
		if bigOrSmall.index(deck_steve[i]) < bigOrSmall.index(deck_josh[i]):
			winJosh += 1
		elif bigOrSmall.index(deck_steve[i]) > bigOrSmall.index(deck_josh[i]):
			winSteve += 1
	if winSteve > winJosh:
		return m.format('Steve', winSteve, winJosh)
	elif winSteve < winJosh:
		return m.format('Josh', winJosh, winSteve)
	else:
		return 'Tie'


ranks = ('2', '3', '4', '5', '6', '7', '8', '9', 'T', 'J', 'Q', 'K', 'A')

def cmp(a, b):
	return (a > b) - (b > a)

def winner(deck_steve, deck_josh):
	points = [0, 0, 0]
	for xs in zip(deck_steve, deck_josh):
		(s, j) = map(ranks.index, xs)
		points[0 if s > j else 1 if s < j else 2] += 1
	if points[0] > points[1]:
		return f'Steve wins {points[0]} to {points[1]}'
	elif points[1] > points[0]:
		return f'Josh wins {points[1]} to {points[0]}'
	else:
		return 'Tie'


def winner(deck_steve, deck_josh):
	deck = [deck_steve, deck_josh]
	score = [e[1] > e[0] for e in zip(*[map('23456789TJQKA'.index, x) for x in deck]) if e[1] != e[0]]
	(l, s, f) = (len(score) / 2, sum(score), score.count(False))
	winer = [('Steve', f, s), ('Josh', s, f)][s > l]
	return 'Tie' if not score or s == l else '{} wins {} to {}'.format(*winer)


def winner(deck_steve, deck_josh):
	ls = ['2', '3', '4', '5', '6', '7', '8', '9', 'T', 'J', 'Q', 'K', 'A']
	st = 0
	jo = 0
	for (k, v) in enumerate(deck_josh):
		if ls.index(v) > ls.index(deck_steve[k]):
			jo += 1
		elif ls.index(v) < ls.index(deck_steve[k]):
			st += 1
	return 'Tie' if st == jo else '{} wins {} to {}'.format('Steve' if st > jo else 'Josh', max(st, jo), min(st, jo))


from numpy import sign
D = {x: i for (i, x) in enumerate('23456789TJQKA')}

def winner(deck_steve, deck_josh):
	res = [0, 0, 0]
	for (s, j) in zip(deck_steve, deck_josh):
		res[sign(D[s] - D[j])] += 1
	return f'Steve wins {res[1]} to {res[2]}' if res[1] > res[2] else f'Josh wins {res[2]} to {res[1]}' if res[1] < res[2] else 'Tie'