# Letterss of Natac
In a game I just made up that doesn’t have anything to do with any other game that you may or may not have played, you collect resources on each turn and then use those resources to build things like roads, settlements and cities. If you would like to try other kata about this game, they can be found **[here](https://www.codewars.com/collections/59e6938afc3c49005900011f)**

## Task

This kata asks you to implement a time efficient version of the function `play_if_enough(hand, play)` , which takes as input a `hand`, the resources you have (a string of letters representing the resources you have), and a `play`, (a string of letters representing the resources required to build a certain game object), and returns a tuple (list in r) of a boolean value, corresponding to whether you have enough resources, and your hand. If you had enough to build the object, the returned hand is your resources minus those you used to build the object. If not, it is your original hand (the one passed to the function).  

For example, if it takes 3 ore and 2 grain to build a city, `play` is `”ooogg”`. If `hand` is `”ooooogggssbbb”`, then `play_if_enough(hand, play)` returns `(True, “oogssbbb”)`. 

## Examples
```python
play_if_enough("ooooogggssbbb", "ooogg")  => (True, "oogssbbb")
play_if_enough("oogssbbb", "bwsg")        => (False, "oogssbbb")
play_if_enough("", "bw")                  => (False, "")
play_if_enough("abcdefghij", "aa")        => (False, "abcdefghij")

```
## Notes: 
1. The order of resources in your hand (or play) is not relevant. You can shuffle your hand any way you'd like, so long as you have the same number of each resource.
2. There are 26 different resources, each represented by a lower case letter a-z, so a valid hand is a string of lower case letters.
3. A valid play is a string of any number of lower case letters.
4. You do not have to test for whether a hand or play is valid. 
5. A hand can be empty, but a play can't. In the event a hand is empty, you don't have the cards to play, so return `(False, "")`, in the correct data structure for your language, see example 4 above.
6. Tests include hand sizes of up to 150000 elements and play sizes up to 10000 elements.

Difficulty: EASY
Tags: Fundamentals

Starter code:
def play_if_enough(hand, play):
	

Solutions:
from collections import Counter

def play_if_enough(hand, play):
	h = Counter(hand)
	p = Counter(play)
	if p & h == p:
		h.subtract(p)
		return (True, ''.join(h.elements()))
	return (False, hand)


from collections import Counter

def play_if_enough(hand, play):
	(hand, play) = (Counter(hand), Counter(play))
	played = not play - hand
	if played:
		hand -= play
	return (played, ''.join(hand.elements()))


from collections import Counter

def play_if_enough(hand, play):
	available = Counter(hand)
	available.subtract(Counter(play))
	if min(available.values()) < 0:
		return (False, hand)
	return (True, ''.join(available.elements()))


def play_if_enough(hand, play):
	a = dict([(x, hand.count(x)) for x in set(hand)])
	b = dict([(x, play.count(x)) for x in set(play)])
	if not False in [a.get(i, 0) > b.get(i, 0) for i in a] and hand != '':
		return (True, ''.join([str(x * (a[x] - b.get(x, 0))) for x in a]))
	return (False, hand)


import collections

def play_if_enough(hand, play):
	(hand_counter, play_counter) = (collections.Counter(hand), collections.Counter(play))
	return (False, hand) if play_counter - hand_counter else (True, ''.join((hand_counter - play_counter).elements()))


def play_if_enough(hand, play):
	p = [hand.count(i) - play.count(i) for i in sorted(set(list(play)))]
	d = all((x >= 0 for x in p))
	h = [i * hand.count(i) for i in sorted(set(list(hand))) if play.count(i) == 0]
	h_p = [i * (hand.count(i) - play.count(i)) for i in sorted(set(list(play)))]
	return (d, ''.join(h + h_p)) if d is True else (d, hand)


def play_if_enough(Q, S):
	R = {}
	for T in Q:
		R[T] = 1 + R[T] if T in R else 1
	for T in S:
		if T not in R or R[T] < 1:
			return (False, Q)
		R[T] -= 1
	return (True, ''.join((V * R[V] for (F, V) in enumerate(R))))


from collections import Counter

def play_if_enough(hand, play):
	(c1, c2) = (Counter(hand), Counter(play))
	if not c2 - c1:
		return (True, ''.join((x * (c1[x] - c2[x]) for x in c1)))
	else:
		return (False, hand)


def play_if_enough(hand, play):
	result = ''
	letter = set(play)
	if len(play) > len(play):
		return (0, hand)
	for i in letter:
		if i not in hand or play.count(i) > hand.count(i):
			return (0, hand)
		hand = hand.replace(i, '', play.count(i))
	return (1, hand)