A lot of goods have an  International Article Number (formerly known as "European Article Number") abbreviated "EAN". EAN is a 13-digits barcode consisting of 12-digits data followed by a single-digit checksum (EAN-8 is not considered in this kata).


The single-digit checksum is calculated as followed (based upon the 12-digit data):

The digit at the first, third, fifth, etc. position (i.e. at the odd position) has to be multiplied with "1". 
The digit at the second, fourth, sixth, etc. position (i.e. at the even position) has to be multiplied with "3".
Sum these results. 

If this sum is dividable by 10, the checksum is 0. Otherwise the checksum has the following formula:

  checksum = 10 - (sum mod 10)

For example, calculate the checksum for "400330101839" (= 12-digits data):

4·1 + 0·3 + 0·1 + 3·3 + 3·1 + 0·3 + 1·1 + 0·3 + 1·1 + 8·3 + 3·1 + 9·3
= 4 + 0 + 0 + 9 + 3 + 0 + 1 + 0 + 1 + 24 + 3 + 27 
= 72
10 - (72 mod 10) = 8 ⇒ Checksum: 8

Thus, the EAN-Code is 4003301018398 (= 12-digits data followed by single-digit checksum).
 
Your Task
Validate a given EAN-Code. Return true if the given EAN-Code is valid, otherwise false.

Assumption
You can assume the given code is syntactically valid, i.e. it only consists of numbers and it exactly has a length of 13 characters.

Examples

```python
validate_ean("4003301018398") # => True
validate_ean("4003301018392") # => False
```

Good Luck and have fun.

Difficulty: EASY
Tags: Fundamentals

Mathematics

Starter code:
def validate_ean(code):
	

Solutions:
validate_ean = lambda code: (sum(map(int, code[0::2])) + sum(map(int, code[1::2])) * 3) % 10 == 0


def validate_ean(code):
	(data, last) = (code[:12], int(code[12]))
	checksum = -sum((int(d) * 3 ** (i % 2) for (i, d) in enumerate(data))) % 10
	return last == checksum


def validate_ean(code):
	checksum = int(code[-1:])
	code = list(map(int, code[:-1]))
	odd = sum([code[i] for i in range(0, len(code), 2)])
	even = sum([code[i] * 3 for i in range(1, len(code), 2)])
	total = odd + even
	if total % 10 == 0:
		if checksum == 0:
			return True
		else:
			return False
	else:
		new_checksum = 10 - total % 10
		if new_checksum == checksum:
			return True
		else:
			return False


def validate_ean(code):
	return sum((x * (i % 2 * 2 + 1) for (i, x) in enumerate(map(int, code)))) % 10 == 0


def validate_ean(code):
	check_digit = int(code[-1])
	code = list(map(int, code[:-1]))
	totals = sum([digit * 3 if pos % 2 == 0 else digit for (pos, digit) in enumerate(code, 1)])
	if totals % 10 == 0:
		checksum = 0
	else:
		checksum = 10 - totals % 10
	return check_digit == checksum


def validate_ean(code):
	return sum([int(x) if i % 2 == 0 else 3 * int(x) for (i, x) in enumerate(code)]) % 10 == 0


def validate_ean(code):
	sum1 = sum(map(int, code[0:-1:2]))
	sum2 = sum(map(lambda x: x * 3, map(int, code[1:-1:2])))
	checksum = 10 - (sum1 + sum2) % 10
	checksum = 0 if checksum == 10 else checksum
	return int(code[-1]) == checksum


def validate_ean(code):
	sum_odd = sum((int(x) for x in code[:-1:2]))
	sum_even = sum((int(x) * 3 for x in code[1::2]))
	checksum = (sum_odd + sum_even) % 10
	if checksum:
		return 10 - checksum == int(code[-1])
	else:
		return checksum == int(code[-1])