# Task

Your task is to write a function for calculating the score of a 10 pin bowling game. The input for the function is a list of pins knocked down per roll for one player. Output is the player's total score.

# Rules

## General rules
Rules of bowling in a nutshell:

* A game consists of 10 frames. In each frame the player rolls 1 or 2 balls, except for the 10th frame, where the player rolls 2 or 3 balls.

* The total score is the sum of your scores for the 10 frames

* If you knock down fewer than 10 pins with 2 balls, your frame score is the number of pins knocked down

* If you knock down all 10 pins with 2 balls (spare), you score the amount of pins knocked down plus a bonus - amount of pins knocked down with the next ball

* If you knock down all 10 pins with 1 ball (strike), you score the amount of pins knocked down plus a bonus - amount of pins knocked down with the next 2 balls

## Rules for 10th frame
As the 10th frame is the last one, in case of spare or strike there will be no next balls for the bonus. To account for that:

* if the last frame is a spare, player rolls 1 bonus ball.
* if the last frame is a strike, player rolls 2 bonus balls.

These bonus balls on 10th frame are only counted as a bonus to the respective spare or strike.

# More information
http://en.wikipedia.org/wiki/Ten-pin_bowling#Scoring

# Input
You may assume that the input is always valid. This means:

* input list length is correct
* number of pins knocked out per roll is valid

Difficulty: EASY
Starter code: def bowling_score(rolls):
	

Solutions:
def bowling_score(rolls):

	def is_spare(rolls):
		return 10 == sum(rolls[:2])

	def is_strike(rolls):
		return 10 == rolls[0]

	def calc_score(rolls, frame):
		return sum(rolls) if frame == 10 else sum(rolls[:3]) + calc_score(rolls[1:], frame + 1) if is_strike(rolls) else sum(rolls[:3]) + calc_score(rolls[2:], frame + 1) if is_spare(rolls) else sum(rolls[:2]) + calc_score(rolls[2:], frame + 1)
	return calc_score(rolls, 1)


def bowling_score(rolls):
	count = 0
	score = 0
	while count < 10:
		count += 1
		frame = rolls.pop(0)
		if frame < 10:
			frame += rolls.pop(0)
			score += frame
			if frame == 10:
				score += rolls[0]
		else:
			score += frame + rolls[0] + rolls[1]
	return score


def bowling_score(rolls):
	(tot, i) = (0, 0)
	for frm in range(10):
		(fscr, i) = (rolls[i], i + 1)
		if fscr == 10:
			tot += fscr + rolls[i] + rolls[i + 1]
			continue
		fscr += rolls[i]
		i += 1
		if fscr >= 10:
			tot += rolls[i]
		tot += fscr
	return tot


def bowling_score(rolls):
	i = score = 0
	for _ in range(10):
		if rolls[i] == 10:
			score += rolls[i] + rolls[i + 1] + rolls[i + 2]
			i += 1
		elif rolls[i] + rolls[i + 1] == 10:
			score += rolls[i] + rolls[i + 1] + rolls[i + 2]
			i += 2
		else:
			score += rolls[i] + rolls[i + 1]
			i += 2
	return score


def bowling_score(rolls):
	score = 0
	for i in range(10):
		frame = rolls.pop(0)
		if frame == 10:
			score += frame + rolls[0] + rolls[1]
		else:
			frame += rolls.pop(0)
			score += frame
			if frame == 10:
				score += rolls[0]
	return score


def bowling_score(s):
	(i, count) = (0, [])
	while len(count) < 9:
		count.append(s[i] + s[i + 1] + [0, s[i + 2]][10 in [s[i] + s[i + 1], s[i]]])
		i += 2 - int(s[i] == 10)
	return sum(count) + sum(s[i:])


def bowling_score(rolls):
	(i, score) = (0, 0)
	for _ in range(10):
		oneBall = frame = rolls[i]
		i += 1
		if oneBall < 10:
			frame += rolls[i]
			i += 1
		if frame == 10:
			score += sum(rolls[i:i + 1 + (oneBall == 10)])
		score += frame
	return score


def bowling_score(rolls):
	score = 0
	frame = 0
	i = 0
	while frame < 10:
		if rolls[i] == 10:
			score += rolls[i] + rolls[i + 1] + rolls[i + 2]
			frame += 1
			i += 1
		else:
			tmp = rolls[i] + rolls[i + 1]
			score += tmp
			if tmp == 10:
				score += rolls[i + 2]
			frame += 1
			i += 2
	return score


def bowling_score(rolls):
	(frames, scores) = (0, 0)
	while frames < 9:
		scores += sum(rolls[:2])
		if 10 in (rolls[0], sum(rolls[:2])):
			scores += rolls[2]
		if rolls[0] != 10:
			rolls.pop(0)
		frames += 1
		rolls.pop(0)
	return scores + sum(rolls)


def bowling_score(rolls):
	frameIndex = 1
	pins = 10
	rollsLeft = 2
	totalScore = 0
	frameScore = 0
	for i in range(len(rolls)):
		if frameIndex <= 10:
			frameScore += rolls[i]
			pins -= rolls[i]
			rollsLeft -= 1
		if pins <= 0:
			if frameIndex <= 10:
				bonus = rollsLeft + 1
				frameScore += sum(rolls[i + 1:i + 1 + bonus])
			frameIndex += 1
			pins = 10
			rollsLeft = 2
			totalScore += frameScore
			frameScore = 0
		elif rollsLeft <= 0:
			frameIndex += 1
			pins = 10
			rollsLeft = 2
			totalScore += frameScore
			frameScore = 0
	return totalScore