# Task

John is playing a RPG game. The initial attack value of the player is `x`. The player will face a crowd of monsters. Each monster has different defense value.

If the monster's defense value is less than or equal to the player's attack value, the player can easily defeat the monster, and the player's attack value will increase. The amount increased is equal to the monster's defense value.

If the monster's defense value is greater than the player's attack value, the player can still defeat monsters, but the player's attack value can only be increased little, equal to the `greatest common divisor` of the monster's defense value and the player's current attack value. 

The defense values for all monsters are provided by `monsterList/monster_list`. The player will fight with the monsters from left to right.

Please help John calculate the player's final attack value.


# Example

For `x = 50, monsterList=[50,105,200]`, the output should be `110`.

The attack value increased: `50 --> 100 --> 105 --> 110`

For `x = 20, monsterList=[30,20,15,40,100]`, the output should be `205`.

The attack value increased: 

`20 --> 30 --> 50 --> 65 --> 105 --> 205`

Source: codewars | Difficulty: EASY
Tags: Ad-hoc

Starter code: def final_attack_value(x,monster_list):
	

Solutions:
from functools import reduce
from fractions import gcd

def final_attack_value(x, monster_list):
	return reduce(lambda a, b: a + (b if b <= a else gcd(a, b)), monster_list, x)


from fractions import gcd

def final_attack_value(x, monster_list):
	for i in monster_list:
		x += gcd(i, x) if i > x else i
	return x


from math import gcd

def final_attack_value(attack, monsters):
	for monster in monsters:
		attack += gcd(attack, monster) if attack < monster else monster
	return attack


def gcd(a, b):
	while b != 0:
		(a, b) = (b, a % b)
	return a

def final_attack_value(x, monster_list):
	for m in monster_list:
		x = x + m if m <= x else x + gcd(x, m)
	return x


final_attack_value = f = lambda x, m: m and f(x + __import__('fractions').gcd(min(m[0], x), m[0]), m[1:]) or x


from functools import reduce
gcd = lambda a, b: gcd(b, a % b) if b else a
final_attack_value = lambda x, m: reduce(lambda a, b: a + b if a >= b else a + gcd(a, b), m, x)


def final_attack_value(x, monster_list):
	for i in monster_list:
		if x >= i:
			x += i
		else:
			a = x
			b = i
			while b:
				(a, b) = (b, a % b)
			x += a
	return x


from math import gcd

def final_attack_value(x, monster_list):
	for m in monster_list:
		if m <= x:
			x += m
		else:
			x += gcd(x, m)
	return x