# Is my barcode valid?

## JavaScript (ES6), ~~41~~ ~~40~~ 38 bytes

*Saved 2 bytes thanks to @ETHProductions and 1 byte thanks to @Craig Ayre.*

```
s=>s.map(e=>t+=e*(i^=2),t=i=1)|t%10==1
```

Takes input as a list of digits.

Determines the sum of all digits, including the checksum.

If the sum is a multiple of 10, then it's a valid barcode.

**Test Cases**

```
let f=
s=>s.map(e=>t+=e*(i^=2),t=i=1)|t%10==1
console.log(f([2,0,3,7,8,2,4,0]));
console.log(f([3,3,7,6,5,1,2,9]));
console.log(f([7,7,2,3,4,5,7,5]));
console.log(f([0,0,0,0,0,0,0,0]));
console.log(f([2,1,0,3,4,9,8,4]));
console.log(f([6,9,1,6,5,4,3,0]));
console.log(f([1,1,9,6,5,4,2,1]));
console.log(f([1,2,3,4,5,6,7,8]));
```

## Python 2, ~~64~~ ~~48~~ ~~35~~ 29 bytes

mypetlion saved 19 bytes

```
lambda x:sum(x[::2]*2+x)%10<1
```

Try it online!

## Jelly, 8 bytes

```
m2Ḥ+µS⁵ḍ
```

**Try the test suite.**

## Jelly, 9 bytes

```
JḂḤ‘×µS⁵ḍ
```

**Try it online** or **Try the test suite.**

### How this works

m2Ḥ+µS⁵ḍ ~ Full program. m2 ~ Modular 2. Return every second element of the input. Ḥ ~ Double each. +µ ~ Append the input and start a new monadic chain. S ~ Sum. ⁵ḍ ~ Is divisible by 10?

JḂḤ‘×µS⁵ḍ ~ Full program (monadic). J ~ 1-indexed length range. Ḃ ~ Bit; Modulo each number in the range above by 2. Ḥ ~ Double each. ‘ ~ Increment each. × ~ Pairwise multiplication with the input. µ ~ Starts a new monadic chain. S ~ Sum. ⁵ḍ ~ Is the sum divisible by 10?

The result for the first 7 digits of the barcode and the checksum digit **must** add to a multiple of **10** for it to be valid. Thus, the checksum is valid iff the algorithm applied to the *whole* list is divisible by **10**.