# 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 settlements, roads, and cities or buy a development. Other kata about this game can be found [here](https://www.codewars.com/collections/59e6938afc3c49005900011f).

## Task
This kata asks you to implement the function `build_or_buy(hand)` , which takes as input a `hand`, the resources you have (a string of letters representing the resources you have), and returns a list of the unique game objects you can build or buy given your hand. 

There are five different resources, `'b'`, `'w'`, `'g'`, `'s'`, and `'o'`.

Game objects and the resources required to build or buy them are as follows:
1. `'road'`: `bw`
2. `'settlement'`: `bwsg`
3. `'city'`: `ooogg`
4. `'development'`: `osg`

## Examples
```python
build_or_buy("bwoo")  => ['road']
build_or_buy("bwsg")  => ['road', 'settlement'] or ['settlement', 'road']
build_or_buy("")      => []
build_or_buy("ogogoogogo")  => ['city']

```

## Notes: 
1. Don't mutate the hand
2. The order of the returned list doesn't matter
3. You do not have to test for whether a hand is valid. 
4. The list will be interpreted to mean 'you can build any of these objects,' not 'you can build all these objects in one play'. See example 2 above, even though there is only one `'b'` and one `'w'` in `hand`, both `Road()` and `Settlement()` are in the list. 
5. A hand can be empty. In the event a hand is empty, you can't build or buy anything, so return an empty list, see example 3 above.
6. Hand are between 0 and 39 in length.

Difficulty: EASY
Starter code: def build_or_buy(hand):
	

Solutions:
from collections import Counter
REQUIRE = {x: Counter(s) for (x, s) in [('road', 'bw'), ('settlement', 'bwsg'), ('city', 'ooogg'), ('development', 'osg')]}

def build_or_buy(hand):
	h = Counter(hand)
	return [item for (item, c) in REQUIRE.items() if not c - h]


def build_or_buy(hand):
	d = {'bw': 'road', 'bwsg': 'settlement', 'ooogg': 'city', 'osg': 'development'}
	res = []
	for (r, build) in d.items():
		if all((hand.count(i) >= r.count(i) for i in set(r))):
			res.append(build)
	return res


def build_or_buy(h):
	l = {'road': 'bw', 'settlement': 'bwsg', 'city': 'ooogg', 'development': 'osg'}
	return [x for x in l if all((l[x].count(y) <= h.count(y) for y in l[x]))] if h else []


from collections import Counter
reqs = {'road': Counter('bw'), 'settlement': Counter('bwsg'), 'city': Counter('ooogg'), 'development': Counter('osg')}

def build_or_buy(hand):
	return list(filter(lambda obj: not reqs[obj] - Counter(hand), reqs.keys()))


def build_or_buy(hand):
	result = []
	(b, w, g, s, o) = [hand.count(st) for st in 'b,w,g,s,o'.split(',')]
	if b and w:
		result.append('road')
		if s and g:
			result.append('settlement')
	if o and g:
		if s:
			result.append('development')
		if o > 2 and g > 1:
			result.append('city')
	return result


from collections import Counter

def build_or_buy(hand):
	res = []
	bank = Counter(hand)
	if bank['b'] > 0 and bank['w'] > 0:
		res.append('road')
		if bank['s'] > 0 and bank['g'] > 0:
			res.append('settlement')
	if bank['o'] > 2 and bank['g'] > 1:
		res.append('city')
	if bank['o'] > 0 and bank['s'] > 0 and (bank['g'] > 0):
		res.append('development')
	return res


def build_or_buy(hand):
	objects = {'road': 'bw', 'settlement': 'bwsg', 'city': 'ooogg', 'development': 'osg'}
	return [key for (key, val) in objects.items() if not any((hand.count(c) < val.count(c) for c in set(val)))]


from collections import Counter as C
r = dict(zip('road settlement city development'.split(), map(C, 'bw bwsg ooogg osg'.split())))
build_or_buy = lambda s: (lambda t: [k for (k, v) in r.items() if all((v[x] <= t[x] for x in v))])(C(s))


def build_or_buy(hand):
	o = {'bw': 'road', 'bwsg': 'settlement', 'ooogg': 'city', 'osg': 'development'}

	def valid(x):
		for c in set(x):
			if hand.count(c) < x.count(c):
				return False
		return True
	return [v for (k, v) in o.items() if valid(k)]