You have stumbled across the divine pleasure that is owning a dog and a garden. Now time to pick up all the cr@p! :D

Given a 2D array to represent your garden, you must find and collect all of the dog cr@p - represented by '@'.

You will also be given the number of bags you have access to (bags), and the capactity of a bag (cap). If there are no bags then you can't pick anything up, so you can ignore cap.

You need to find out if you have enough capacity to collect all the cr@p and make your garden clean again. 

If you do, return 'Clean', else return 'Cr@p'.

Watch out though - if your dog is out there ('D'), he gets very touchy about being watched. If he is there you need to return 'Dog!!'.

For example:

x=
[[\_,\_,\_,\_,\_,\_]
 [\_,\_,\_,\_,@,\_]
 [@,\_,\_,\_,\_,\_]]

bags = 2, cap = 2

return  --> 'Clean'

Source: codewars | Difficulty: EASY
Tags: String algorithms

Fundamentals

Data structures

Mathematics

Starter code: def crap(garden, bags, cap):
	

Solutions:
def crap(garden, bags, cap):
	cap *= bags
	for turf in garden:
		if 'D' in turf:
			return 'Dog!!'
		cap -= turf.count('@')
	return 'Cr@p' if cap < 0 else 'Clean'


from collections import Counter
from itertools import chain

def crap(garden, bags, cap):
	c = Counter(chain(*garden))
	return 'Dog!!' if c['D'] else ('Clean', 'Cr@p')[c['@'] > bags * cap]


def crap(garden, bags, cap):
	for each in garden:
		for i in each:
			if i == 'D':
				return 'Dog!!'
	a = 0
	for each in garden:
		for i in each:
			if i == '@':
				a += 1
	b = bags * cap
	if a > b:
		return 'Cr@p'
	else:
		return 'Clean'


def crap(garden, bags, cap):
	flat = [e for line in garden for e in line if e in 'D@']
	return 'Dog!!' if 'D' in flat else 'Clean' if len(flat) <= bags * cap else 'Cr@p'


def crap(g, b, c):
	g = sum(g, [])
	if 'D' in g:
		return 'Dog!!'
	return 'Clean' if g.count('@') <= b * c else 'Cr@p'


def crap(garden, bags, cap):
	count_crap = 0
	for x in garden:
		for y in x:
			if y == 'D':
				return 'Dog!!'
			if y == '@':
				count_crap += 1
	if bags * cap >= count_crap:
		return 'Clean'
	else:
		return 'Cr@p'


def crap(garden, bags, cap):
	s = ''.join([''.join(i) for i in garden])
	return 'Dog!!' if 'D' in s else 'Clean' if s.count('@') <= bags * cap else 'Cr@p'


crap = lambda g, b, c, l=[]: l.clear() or [l.extend(e) for e in g][0] or ['Clean', 'Cr@p', 'Dog!!'][('D' in l) * 2 or l.count('@') > b * c]


from itertools import chain

def crap(garden, bags, cap):
	return (lambda x: 'Dog!!' if x.count('D') else 'Clean' if x.count('@') <= bags * cap else 'Cr@p')(list(chain(*garden)))


def crap(garden, bags, cap):
	for each in garden:
		for i in each:
			if i == 'D':
				return 'Dog!!'
	count = 0
	for each in garden:
		for i in each:
			if i == '@':
				count += 1
	count_caps = bags * cap
	if count > count_caps:
		return 'Cr@p'
	else:
		return 'Clean'