Learning to code around your full time job is taking over your life. You realise that in order to make significant steps quickly, it would help to go to a coding bootcamp in London.

Problem is, many of them cost a fortune, and those that don't still involve a significant amount of time off work - who will pay your mortgage?!

To offset this risk, you decide that rather than leaving work totally, you will request a sabbatical so that you can go back to work post bootcamp and be paid while you look for your next role.

You need to approach your boss. Her decision will be based on three parameters:

val=your value to the organisation
happiness=her happiness level at the time of asking and finally
The numbers of letters from 'sabbatical' that are present in string `s`.

Note that if `s` contains three instances of the letter 'l', that still scores three points, even though there is only one in the word sabbatical.

If the sum of the three parameters (as described above) is > 22, return 'Sabbatical! Boom!', else return 'Back to your desk, boy.'.

~~~if:c
NOTE: For the C translation you should return a string literal.
~~~

Source: codewars | Difficulty: EASY
Tags: String algorithms

Fundamentals

Data structures

Mathematics

Starter code: def sabb(s, value, happiness):
	

Solutions:
def sabb(stg, value, happiness):
	sabbatical = value + happiness + sum((1 for c in stg if c in 'sabbatical')) > 22
	return 'Sabbatical! Boom!' if sabbatical else 'Back to your desk, boy.'


def sabb(s, value, happiness):
	score = sum((c in 'sabticl' for c in s.lower())) + value + happiness
	return 'Sabbatical! Boom!' if score > 22 else 'Back to your desk, boy.'


SABBATICAL = set('sabbatical')

def sabb(s, value, happiness):
	if value + happiness + sum((c in SABBATICAL for c in s)) > 22:
		return 'Sabbatical! Boom!'
	else:
		return 'Back to your desk, boy.'


def sabb(s, value, happiness):
	return 'Sabbatical! Boom!' if sum([sum((1 for i in s if i in 'sabbatical')), value, happiness]) > 22 else 'Back to your desk, boy.'


from collections import Counter

def sabb(s, value, happiness):
	cnt = Counter(s.lower())
	return ('Back to your desk, boy.', 'Sabbatical! Boom!')[sum((cnt[a] for a in set('sabbatical'))) + value + happiness > 22]


from collections import Counter

def sabb(s, value, happiness):
	C = Counter(s.lower())
	score = value + happiness + sum((C[c] for c in set('sabbatical')))
	return 'Sabbatical! Boom!' if score > 22 else 'Back to your desk, boy.'


def sabb(s, value, happiness):
	nb = len(list((c for c in s.lower() if c in 'sabticl')))
	return ['Back to your desk, boy.', 'Sabbatical! Boom!'][nb + value + happiness > 22]


def sabb(s, value, happiness):
	sab = []
	for x in s:
		if x == 's' or x == 'a' or x == 'b' or (x == 't') or (x == 'i') or (x == 'c') or (x == 'l'):
			sab.append(1)
		else:
			sab.append(0)
	z = sum(sab)
	y = z + value + happiness
	if y <= 22:
		return 'Back to your desk, boy.'
	else:
		return 'Sabbatical! Boom!'


def sabb(s, v, h):
	ss = sum((1 for i in s if i in 'sabbatical'))
	return ('Back to your desk, boy.', 'Sabbatical! Boom!')[sum([ss, v, h]) > 22]