[Question]
  [
An [EAN-8](https://en.wikipedia.org/wiki/EAN-8) barcode includes 7 digits of information and an 8th checksum digit.
The checksum is calculated by multiplying the digits by 3 and 1 alternately, adding the results, and subtracting from the next multiple of 10.
For example, given the digits `2103498`:
```
Digit:        2   1   0   3   4   9   8
Multiplier:   3   1   3   1   3   1   3
Result:       6   1   0   3  12   9  24
```
The sum of these resulting digits is **55**, so the checksum digit is **60 - 55 = 5**
---
# The Challenge
Your task is to, given an 8 digit barcode, verify if it is valid - returning a truthy value if the checksum is valid, and falsy otherwise.
* You may take input in any of the following forms:
	+ A string, 8 characters in length, representing the barcode digits
	+ A list of 8 integers, the barcode's digits
	+ A non-negative integer (you can either assume leading zeroes where none are given, i.e. `1` = `00000001`, or request input with the zeroes given)
* Builtins that compute the EAN-8 checksum (i.e, take the first 7 digits and calculate the last) are banned.
* This is [code-golf](/questions/tagged/code-golf "show questions tagged 'code-golf'"), so the shortest program (in bytes) wins!
---
# Test Cases
```
20378240 -> True
33765129 -> True
77234575 -> True
00000000 -> True
21034984 -> False
69165430 -> False
11965421 -> False
12345678 -> False
```
  
[Answer]
# 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]));
```
[Answer]
# [Python 2](https://docs.python.org/2/), 64 48 35 29 bytes
[mypetlion](https://codegolf.stackexchange.com/users/65255/mypetlion) saved 19 bytes
```
lambda x:sum(x[::2]*2+x)%10<1
```
[Try it online!](https://tio.run/##Vc5LDoIwEADQtT1FNyags2hLAWnkJNgYVIgk8gmtCZ6@jhQxZlbz5ju87L3vhKvzk3uU7eVW0kmZZxtMhVJC78R@CrecHbmzlbHna2kqQ3NakE0hgEEEKRxAgASmgSJGMyUQA0fOPKZIAgsSOYXYI4O/8ChwjM2dGe6VHhNM@LxTYgk70ThKthgOLfY9knze0kQTUvcjXT@nTfdLjCJ0GJvOBnWwYhi6Nw "Python 2 – Try It Online")
[Answer]
# [Jelly](https://github.com/DennisMitchell/jelly), 8 bytes
```
m2Ḥ+µS⁵ḍ
```
**[Try the test suite.](https://tio.run/##y0rNyan8/z/X6OGOJdqHtgY/atz6cEfv/8Ptj5rWuP//Hx1tpKNgoKNgrKNgrqNgoaMA5JoARWJ1uLiijWHiZjoKpjoKhmBZS7CUOVjcCKzABCwL5JqCpSB6jcDqDWAKLMGGm4ClzMBcQ5ixJmA1EF2GYHFLJCmQOTApZOvMIA6O5YoFAA "Jelly – Try It Online")**
# [Jelly](https://github.com/DennisMitchell/jelly), 9 [bytes](https://github.com/DennisMitchell/jelly/wiki/Code-page)
```
JḂḤ‘×µS⁵ḍ
```
**[Try it online](https://tio.run/##y0rNyan8/9/r4Y6mhzuWPGqYcXj6oa3Bjxq3PtzR@///f2MdBSAy11Ew01Ew1VEw1FEw0lGwBAA)** or **[Try the test suite.](https://tio.run/##y0rNyan8/9/r4Y6mhzuWPGqYcXj6oa3Bjxq3PtzR@/9w@6OmNe7//0dHG@koGOgoGOsomOsoWOgoALkmQJFYHS6uaGOYuJmOgqmOgiFY1hIsZQ4WNwIrMAHLArmmYCmIXiOwegOYAkuw4SZgKTMw1xBmrAlYDUSXIVjcEkkKZA5MCtk6M4iDY7liAQ "Jelly – Try It Online")**
## 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**.
[Answer]
# [MATL](https://github.com/lmendo/MATL), 10 bytes
*Thanks to [@Zgarb](https://codegolf.stackexchange.com/users/32014/zgarb) for pointing out a mistake, now corrected.*
```
IlhY"s10\~
```
[Try it online!](https://tio.run/##y00syfn/3zMnI1Kp2NAgpu7//2gjBUMFAwVjBRMFSwULBdNYAA) Or [verify all test cases](https://tio.run/##Vc4xDoAgFAPQ3VM0nuCDCLK7uLsYNNHNASedvToWooNh@X1pGo7timlNQ9yn@lQy36kfU9AQNHDooGEgSxWaki1aKJqnOGZNNTSHliL4PYpmW0rHc8tQLC9Vdgw9dxSzf4X9It@uzX9YHg).
### Explanation
```
Ilh     % Push [1 3]
Y"      % Implicit input. Run-length decoding. For each entry in the
        % first input, this produces as many copies as indicated by
        % the corresponding entry of the second input. Entries of
        % the second input are reused cyclically
s       % Sum of array
10\     % Modulo 10
~       % Logical negate. Implicit display
```
[Answer]
# [Befunge-98 (PyFunge)](https://pythonhosted.org/PyFunge/), ~~16~~ 14 bytes
Saved 2 bytes by skipping the second part using `j` instead of `;`s, as well as swapping a `~` and `+` in the first part to get rid of a `+` in the second.
```
~3*+~+6jq!%a+2
```
Input is in 8 digits (with leading 0s if applicable) and nothing else.
Outputs via exit code (open the debug dropdown on TIO), where 1 is true and 0 is false.
[Try it online!](https://tio.run/##S0pNK81LT9W1tNAtqAQz//@vM9bSrtM2yypUVE3UNvr/39zcyNjE1NwUAA "Befunge-98 (PyFunge) – Try It Online")
## Explanation
This program uses a variety of tricks.
First of all, it takes the digits in one by one through their ASCII values. Normally, this would require subtracting 48 from each value as we read it from the input. However, if we don't modify it, we are left with 16 (3+1+3+1+3+1+3+1) extra copies of 48 in our sum, meaning our total is going to be 768 greater than what it "should" be. Since we are only concerned with the sum mod 10, we can just add 2 to the sum later. Thus, we can take in raw ASCII values, saving 6 bytes or so.
Secondly, this code only checks if every other character is an EOF, because the input is guaranteed to be only 8 characters long.
~~Thirdly, the `#` at the end of the line doesn't skip the first character, but will skip the `;` if coming from the other direction. This is better than putting a `#;` at the front instead.~~
Because the second part of our program is only run once, we don't have to set it up so that it would skip the first half when running backwards. This lets us use the jump command to jump over the second half, as we exit before executing it going backwards.
### Step by step
Note: "Odd" and "Even" characters are based on a 0-indexed system. The first character is an even one, with index 0.
```
~3*+~+      Main loop - sum the digits (with multiplication)
~           If we've reached EOF, reverse; otherwise take char input. This will always
                be evenly indexed values, as we take in 2 characters every loop.
 3*+        Multiply the even character by 3 and add it to the sum.
    ~       Then, take an odd digit - we don't have to worry about EOF because
                the input is always 8 characters.
     +      And add it to the sum.
      6j    Jump over the second part - We only want to run it going backwards.
        q!%a+2    The aftermath (get it? after-MATH?)
            +2    Add 2 to the sum to make up for the offset due to reading ASCII
          %a      Mods the result by 10 - only 0 if the bar code is valid
         !        Logical not the result, turning 0s into 1s and anything else into 0s
        q         Prints the top via exit code and exits
```
[Answer]
# C, ~~78~~ 77 bytes
```
i,s,c,d=10;f(b){for(i=s=0,c=b%d;b/=d;)s+=b%d*(3-i++%2*2);return(d-s%d)%d==c;}
```
[Try it online!](https://tio.run/##dc5NDoMgEAXgvacwJiSgmPInaAg36aZCaVjUNmhXxrNbTd1VZjfzvmSerR/WrmvAI7bYGUq0hz2a/SvCYEZDsDU9cLq/GKfRWO1LCXkdqgqwkiEd79MnDtDVI3AIOGOsXtYwTPnzFgaIsjnLt3nH7eRhAdx1KHDuISNctUwQhPQ54FzJhrIuCZRiXDSqOQMHIcfsJFGDEi66ViS/yI7KRvB0T0q7DTD6D37xXlKqdo@X9Qs)
# C (gcc), 72 bytes
```
i,s,c,d=10;f(b){for(i=s=0,c=b%d;b/=d;)s+=b%d*(i++%2?:3);b=(d-s%d)%d==c;}
```
[Try it online!](https://tio.run/##dc5NCoMwEAXgvacQIZDUSPMfbQi9SDc1ISWL2mK6E8@eKnVXnd3M@2Ceax7O5Rxxwg57S4kJsEdTeI0w2mQJdrYH3vRn6w1K9bqcYKxrwK4XjkxvoW8S8Ah4a52Zcxw@5fMeB4iKqSiXeY/LKcAK@NtQ4TJARrhumSAImX3AuVaSsu4QaM24kFrugY2QbVZyUIMSLrpWHH5RHVVS8OOelHYLYPQf/OK1pNLtGs/5Cw)
[Answer]
# [Wolfram Language (Mathematica)](https://www.wolfram.com/wolframscript/), ~~26~~ 21 bytes
```
10∣(2-9^Range@8).#&
```
[Try it online!](https://tio.run/##y00syUjNTSzJTE78n1aaZ/vf0OBRx2INI13LuKDEvPRUBwtNPWW1/wFFmXkl0UAFCvoOCtVcCgrVRjoKBjoKxjoK5joKFjoKQK4JUKRWRwEkaQyTMdNRMNVRMATLW0IlzcEyRmAlJmB5INcUKmkANhYdQSWNwEYZwHRagm02gUqagQUMYXaagFXBdBqCZSyRJEFmISSRXWMG8VNtbex/AA "Wolfram Language (Mathematica) – Try It Online")
Takes input as a list of 8 digits.
## How it works
`2-9^Range@8` is congruent modulo 10 to `2-(-1)^Range@8`, which is `{3,1,3,1,3,1,3,1}`. We take the dot product of this list with the input, and check if the result is divisible by 10.
# [Wolfram Language (Mathematica)](https://www.wolfram.com/wolframscript/), 33 bytes and non-competing
```
Check[#~BarcodeImage~"EAN8";1,0]&
```
[Try it online!](https://tio.run/##LcvLCsIwFATQXwkRXBXMzc0TEXzgwo24L12EmNoiqVDiSuyvx6Y4q8MwE13qQnSp9y6372GXT13wz3o1Hd3oX/dwie4RJno@XA3dQsWadb6N/ZDqeUw2e/KhnKE2XDBaEYqolQRui7XmKKQsZP8Uc2AorBHFyoKSApcewM7msLg8lTb02@Qf "Wolfram Language (Mathematica) – Try It Online")
Takes input as a string. Returns `1` for valid barcodes and `0` for invalid ones.
## How it works
The best thing I could find in the way of a built-in (since Mathematica is all about those). 
The inside bit, `#~BarcodeImage~"EAN8";1`, generates an image of the EAN8 barcode, then ignores it entirely and evaluates to 1. However, if the barcode is invalid, then `BarcodeImage` generates a warning, which `Check` catches, returning 0 in that case. 
[Answer]
# [Jelly](https://github.com/DennisMitchell/jelly), 7 bytes
```
s2Sḅ3⁵ḍ
```
[Try it online!](https://tio.run/##y0rNyan8/7/YKPjhjlbjR41bH@7o/f9w9xa3sEdNa4otDrcDKff//9XV1bmMDIzNLYxMDLiMjc3NTA2NLLnMzY2MTUzNTbkMoICLy8jQwNjE0sKEy8zS0MzUxNiAy9DQEsgwMuQyBCk2M7fgAhoGAA "Jelly – Try It Online")
### How it works
```
s2Sḅ3⁵ḍ  Main link. Argument: [a,b,c,d,e,f,g,h] (digit array)
s2       Split into chunks of length 2, yielding [[a,b], [c,d], [e,f], [g,h]].
  S      Take the sum of the pairs, yielding [a+c+e+g, b+d+f+h].
   ḅ3    Convert from ternary to integer, yielding 3(a+c+e+g) + (b+d+f+h).
     ⁵ḍ  Test if the result is divisible by 10.
```
[Answer]
# [Haskell](https://www.haskell.org/), 40 38 bytes
```
a=3:1:a
f x=mod(sum$zipWith(*)a x)10<1
```
[Try it online!](https://tio.run/##y0gszk7Nyfn/P02hwjY3P0WjuDRXpSqzIDyzJENDS1MjuTI5JzXaWMcwVrNC09DAxvB/bmJmnoKtQkFpSXBJkU@egopCcUZ@OZBKU4g20jHQMdYx17HQMdIx0TGI/Q8A "Haskell – Try It Online")
Takes input as a list of 8 integers. A practical example of using infinite lists.
Edit: Saved 2 bytes thanks to GolfWolf
[Answer]
# Java 8, ~~58~~ ~~56~~ 55 bytes
```
a->{int r=0,m=1;for(int i:a)r+=(m^=2)*i;return r%10<1;}
```
-2 bytes indirectly thanks to *@RickHitchcock*, by using `(m=4-m)*i` instead of `m++%2*2*i+i` after seeing it in his [JavaScript answer](https://codegolf.stackexchange.com/a/148200/52210).  
-1 byte indirectly thanks to *@ETHProductions* (and *@RickHitchcock*), by using `(m^=2)*i` instead of `(m=4-m)*i`.
**Explanation:**
[Try it here.](https://tio.run/##ldFPT4MwFADw@z7Fu5iAvhHKGIiI38BddjSadKwzndCSUmYM4bPjo5tLvLEUDuXxe3/aIz/xpW6EOu6/xrLibQuvXKp@ASCVFebASwGbaQuw07oSXEHpUejtHbif0/eBXnpay60sYQMKChj58qWnn8AUIdYFyw/aTAjkE/fNQ@HVH0Xk38vcCNsZBeaOhc8sH8b8nKzpdhUlu@Q8abmHmrryttZI9elKn1va/rRW1IHubNBQyFbKU0HpKfENrsc@whBXmOIjRhhjOPiu5xlw5ViCa2REs/kwJRYRjommuJ4PQ/y3rnDuoMyNGmNGw8bzyyYEmBs0Jn7DCTFi2QVS9Vvg3/kk081c4LAYxl8)
```
a->{              // Method with integer-array parameter and boolean return-type
  int r=0,        //  Result-sum
      m=1;        //  Multiplier
  for(int i:a)    //  Loop over the input-array
    r+=           //   Add to the result-sum:
       (m^=2)     //    Either 3 or 1,
       *i;        //    multiplied by the digit
                  //  End of loop (implicit / single-line body)
  return r%10<1;  //  Return if the trailing digit is a 0
}                 // End of method
```
[Answer]
# [05AB1E](https://github.com/Adriandmen/05AB1E), 14 bytes
```
θ¹¨3X‚7∍*O(T%Q
```
[Try it online!](https://tio.run/##MzBNTDJM/f//3I5DOw@tMI541DDL/FFHr5a/Rohq4P//0cY6CkBkrqNgpqNgqqNgqKNgpKNgGQsA "05AB1E – Try It Online")
Needs leading `0`s, takes list of digits.
[Answer]
# [Pyth](https://github.com/isaacg1/pyth), 8 bytes
```
!es+*2%2
```
**[Verify all the test cases!](https://pyth.herokuapp.com/?code=%21es%2B%2a2%252&test_suite=1&test_suite_input=%5B2%2C+0%2C+3%2C+7%2C+8%2C+2%2C+4%2C+0%5D%0A%0A%5B3%2C+3%2C+7%2C+6%2C+5%2C+1%2C+2%2C+9%5D%0A%0A%5B7%2C+7%2C+2%2C+3%2C+4%2C+5%2C+7%2C+5%5D%0A%0A%5B0%5D%0A%0A%5B2%2C+1%2C+0%2C+3%2C+4%2C+9%2C+8%2C+4%5D%0A%0A%5B6%2C+9%2C+1%2C+6%2C+5%2C+4%2C+3%2C+0%5D%0A%0A%5B1%2C+1%2C+9%2C+6%2C+5%2C+4%2C+2%2C+1%5D%0A%0A%5B1%2C+2%2C+3%2C+4%2C+5%2C+6%2C+7%2C+8%5D%0A&debug=0&input_size=2)**
# [Pyth](https://github.com/isaacg1/pyth), 13 bytes
If we can assume the input always has exactly 8 digits:
```
!es.e*bhy%hk2
```
**[Verify all the test cases!](https://pyth.herokuapp.com/?code=%21es.e%2abhy%25hk2&test_suite=1&test_suite_input=%5B2%2C+0%2C+3%2C+7%2C+8%2C+2%2C+4%2C+0%5D%0A%0A%5B3%2C+3%2C+7%2C+6%2C+5%2C+1%2C+2%2C+9%5D%0A%0A%5B7%2C+7%2C+2%2C+3%2C+4%2C+5%2C+7%2C+5%5D%0A%0A%5B0%5D%0A%0A%5B2%2C+1%2C+0%2C+3%2C+4%2C+9%2C+8%2C+4%5D%0A%0A%5B6%2C+9%2C+1%2C+6%2C+5%2C+4%2C+3%2C+0%5D%0A%0A%5B1%2C+1%2C+9%2C+6%2C+5%2C+4%2C+2%2C+1%5D%0A%0A%5B1%2C+2%2C+3%2C+4%2C+5%2C+6%2C+7%2C+8%5D%0A&debug=0&input_size=2)**
---
# How does this work?
```
!es+*2%2 ~ Full program.
      %2 ~ Input[::2]. Every second element of the input.
    *2   ~ Double (repeat list twice).
   +     ~ Append the input.
  s      ~ Sum.
 e       ~ Last digit.
!        ~ Logical NOT.
```
```
!es.e*sbhy%hk2 ~ Full program.
               ~ Convert the input to a String.
   .e          ~ Enumerated map, storing the current value in b and the index in k.
          %hk2 ~ Inverted parity of the index. (k + 1) % 2.
        hy     ~ Double, increment. This maps odd integers to 1 and even ones to 3.
      b        ~ The current digit.
     *         ~ Multiply.
  s            ~ Sum.
 e             ~ Last digit.
!              ~ Logical negation.
```
If the sum of the first 7 digit after being applied the algorithm is subtracted from **10** and then compared to the last digit, this is equivalent to checking whether the sum of all the digits, after the algorithm is applied is a multiple of **10**.
[Answer]
# [Retina](https://github.com/m-ender/retina), ~~23~~ 22 bytes
*-1 byte thanks to [Martin Ender](https://codegolf.stackexchange.com/users/8478/martin-ender)!*
```
(.).
$1$1$&
.
$*
M`
1$
```
[Try it online!](https://tio.run/##LYoxEsIwDAT7e0fIJBQZnSRb9gtS8YdQUNBQMPm/MDPZbbbY7@t8f555W/Yjl23dMHE4Y8QdjwOcMlUsmrrALGqhdkSoeYkCuYBSzHtz1M5a3ARkH6EE/2@Nlj8 "Retina – Try It Online")
### Explanation
Example input: `20378240`
```
(.).
$1$1$&
```
Replace each couple of digits with the first digit repeated twice followed by the couple itself.
We get `2220333788824440`
```
.
$*
```
Convert each digit to unary. With parentheses added for clarity, we get `(11)(11)(11)()(111)(111)...`
```
M`
```
Count the number of matches of the empty string, which is one more than the number of ones in the string. (With the last two steps we have basically taken the sum of each digit +1) Result: `60`
```
1$
```
Match a `1` at the end of the string. We have multiplied digits by 3 and 1 alternately and summed them, for a valid barcode this should be divisible by 10 (last digit 0); but we also added 1 in the last step, so we want the last digit to be 1. Final result: `1`.
[Answer]
# [PowerShell](https://github.com/TryItOnline/TioSetup/wiki/Powershell), 85 bytes
```
param($a)(10-(("$a"[0..6]|%{+"$_"*(3,1)[$i++%2]})-join'+'|iex)%10)%10-eq+"$("$a"[7])"
```
[Try it online!](https://tio.run/##K8gvTy0qzkjNyfn/vyCxKDFXQyVRU8PQQFdDQ0klUSnaQE/PLLZGtVpbSSVeSUvDWMdQM1olU1tb1Si2VlM3Kz8zT11bvSYztUJT1dAAhHVTC4FqIZrNYzWV/v//b2hkbGJqZm4BAA "PowerShell – Try It Online") or [Verify all test cases](https://tio.run/##LYzRCoIwGIVfRcbErc34/21uetOLiMQILaO0tCgwn30pdeDAufjOd@tf9TCe6sslNM/u8Gj7LmqmcPODvzLqOUNIGSPUkxK2W1t94kkQuicbpiXykrZCxKqaeXru2y4Ryaet3zxGWJvW94X9nV3FSZipH45jCatlkUTpLiKCNRHd8zkEBdrlyoDU2tkMVSGdU9pkLpMJ/JNIhaBNkRtpC7SZ0SARi2UolLjS1uVf "PowerShell – Try It Online")
Implements the algorithm as defined. Takes input `$a`, pulls out each digit with `"$a"[0..6]` and loops through them with `|%{...}`. Each iteration, we take the digit, cast it as a string `"$_"` then cast it as an int `+` before multiplying it by either `3` or `1` (chosen by incrementing `$i` modulo `2`).
Those results are all gathered together and summed `-join'+'|iex`. We take that result mod `10`, subtract that from `10`, and again take the result mod `10` (this second mod is necessary to account for the `00000000` test case). We then check whether that's `-eq`ual to the last digit. That Boolean result is left on the pipeline and output is implicit.
[Answer]
# [Jelly](https://github.com/DennisMitchell/jelly), 16 bytes
```
ż3,1ṁ$P€SN%⁵
Ṫ=Ç
```
[Try it online!](https://tio.run/##y0rNyan8///oHmMdw4c7G1UCHjWtCfZTfdS4levhzlW2h9v/uxxuVwEK/v8fzcVpZGBsbmFkYqCjYGxsbmZqaGSpo2BubmRsYmpuqqNgAAU6XECVhgbGJpYWJjoKZpaGZqYmxkA9hoaWQJaRIZAF0mJmbsEVCwA "Jelly – Try It Online")
takes input as a list of digits
[Answer]
# [APL (Dyalog)](https://www.dyalog.com/), 14 bytes
Equivalent with [streetster's solution](https://codegolf.stackexchange.com/a/148270/43319).
Full program body. Prompts for list of numbers from STDIN.
```
0=10|+/⎕×8⍴3 1
```
[Try it online!](https://tio.run/##SyzI0U2pTMzJT///qKPd1dHvv4GtoUGNtv6jvqmHp1s86t1irGAIkvqvAAZAFVxGCgYKxgrmChYKRgomCgZcCBljsLiZgqmCIVDOEknGHChuBJQ1AcqZK5giyRgooEAuZHsMwTaZKFgC7TJBkjEDihiC7TEByiPrMQSKW0JlgPpRZGD2m4HcDgA "APL (Dyalog Unicode) – Try It Online")
***Is…***
 `0=` zero equal to
 `10|` the mod-10 of
 `+/` the sum of
 `⎕×` the input times
 `8⍴3 1` eight elements cyclically taken from `[3,1]`
***?***
[Answer]
# [05AB1E](https://github.com/Adriandmen/05AB1E), 9 bytes
```
3X‚7∍*OTÖ
```
[Try it online!](https://tio.run/##MzBNTDJM/f/fOOJRwyzzRx29Wv4hh6f9/x9trGOsY65jpmOqY6hjpGMZCwA "05AB1E – Try It Online")
```
3X‚7∍*OTÖ    # Argument a
3X‚          # Push [3, 1]
   7∍        # Extend to length 7
     *       # Multiply elements with elements at same index in a
      O      # Total sum
       TÖ    # Divisible by 10
```
[Answer]
# J, 17 bytes
*-10 bytes thanks to cole*
```
0=10|1#.(8$3 1)*]
```
[Try it online!](https://tio.run/##Zc29CsIwFMXxPU9xiMK1IuHefLeQR3ESU3Fx6KrPHisWh3jgLL/lf291QZnAWN@4CD9lZw557yDD8dwGpQ2ololwwmtCXZSai4E2mpW6Xm4PCAoqZpBll7L1TJ07l2IQO/aeknU@pNA7b6MtwL@AfAvUeRwlBu@4d5FxdSt//unGlKm9AQ "J – Try It Online")
This uses multiplication of equal sized lists to avoid the zip/multiply combo of the original solution, as well as the "base 1 trick" `1#.` to add the products together. The high level approach is similar to the original explanation.
## original, 27 bytes
```
0=10|{:+[:+/[:*/(7$3 1),:}:
```
[Try it online!](https://tio.run/##Zc2xDoIwEMbxvU9xISanQuCupT24pE/CaCzGxYFRefaKkTjUL/mW3/K/57RAVCDYnikyvZ5aT1p3k567oxwc8KnRVfPJVC1giorQwKqQFmPm2ELVVmTM9XJ7AEOEBDOgJSeD7QkLd06CZzuWLmJd78WXTvtwD9AvwN8CFh5GDr53VDrzuLnlP/90gwyY3w "J – Try It Online")
## explained
```
0 =                                        is 0 equal to... 
    10 |                                   the remainder when 10 divides...
         {: +                              the last input item plus...
              [: +/                        the sum of...
                    [: */                  the pairwise product of...
                          7$(3 1) ,:       3 1 3 1 3 1 3 zipped with...
                                     }:    all but the last item of the input
```
[Answer]
# C (gcc), ~~84~~ ~~82~~ ~~72~~ ~~61~~ 54 bytes
```
c;i;f(x){for(i=c=0;x;x/=10)c+=(1+2*i++%4)*x;c=c%10<1;}
```
-21 bytes from [Neil](https://codegolf.stackexchange.com/users/17602/neil)
-7 bytes from [Nahuel Fouilleul](https://codegolf.stackexchange.com/users/70745/nahuel-fouilleul)
[Try it online!](https://tio.run/##XZDvaoMwFMU/61OEgpAYt@Ym8R9pnsTJkFQ7hdmhMmTis7vY1k6WD0l@514O91zzcjFmWYyqVYVHMlXXDtfaaKZGNR41MGKoxkC5X1PqSeKPymjjATuBmpe6HdBnUbd4/RTdxQTIfBQd8n0L3wRNrrNWhrIf3k3Rl32W5hnPkV4rzsSZiBMuWQBzsLIQcRQCTzeOYy5kGIcboztHG7PH2ZgDEzJNZMDuHKUQhVKwjQFSyxyevNpFcbLxk1xnVq5jd4FuyRo7MFP2OaG@/imvFf5LRI4Pyd9pClHa3OI7X511qPChwt5rcibWyTsjvd5v7SHYr6bJM5YHaG9@18j/NsiJHW925@UX "C (gcc) – Try It Online")
Developed independently of [Steadybox's answer](https://codegolf.stackexchange.com/a/148187/44694)
'f' is a function that takes the barcode as an `int`, and returns `1` for True and `0` for False.
* `f` stores the last digit of `x` in `s` (`s=x%10`),
* Then calculates the sum in `c` (`for(i=c=0;x;x/=10)c+=(1+2*i++%4)*x;`)
	+ `c` is the sum, `i` is a counter
	+ for each digit including the first, add `1+2*i%4` times the digit (`x%10`) to the checksum and increment `i` (the `i++` in `3-2*i++%4`)
	
	
		- `1+2*i%4` is 1 when `i` is even and 0 when `i` is odd
* Then returns whether the sum is a multiple of ten, and since we added the last digit (multiplied by 1), the sum will be a multiple of ten iff the barcode is valid. (uses GCC-dependent undefined behavior to omit `return`).
[Answer]
# C, 63 bytes
```
i;s=0;c(int*v){for(i=0;i<8;i++){s+=v[i]*3+v[++i];}return s%10;}
```
Assumes that `0` is `true` and any other value is `false`.
## +3 bytes for better return value
```
i;s=0;c(int*v){for(i=0;i<8;i++){s+=v[i]*3+v[++i];}return s%10==0;}
```
Add `==0` to the `return` statement.
## Ungolfed
```
int check(int* values)
{
    int result = 0;
    for (int index = 0; index < 8; index++)
    {
        result += v[i] * 3 + v[++i]; // adds this digit times 3 plus the next digit times 1 to the result
    }
    return result % 10 == 0; // returns true if the result is a multiple of 10
}
```
This uses the alternative definition of EAN checksums where the check digit is chosen such that the checksum of the entire barcode including the check digit is a multiple of 10. Mathematically this works out the same but it's a lot simpler to write.
## Initialising variables inside loop as suggested by Steadybox, 63 bytes
```
i;s;c(int*v){for(i=s=0;i<8;i++){s+=v[i]*3+v[++i];}return s%10;}
```
## Removing curly brackets as suggested by Steadybox, 61 bytes
```
i;s;c(int*v){for(i=s=0;i<8;i++)s+=v[i]*3+v[++i];return s%10;}
```
## Using `<1` rather than `==0` for better return value as suggested by Kevin Cruijssen
```
i;s=0;c(int*v){for(i=0;i<8;i++){s+=v[i]*3+v[++i];}return s%10<1;}
```
Add `<1` to the `return` statement, this adds only 2 bytes rather than adding `==0` which adds 3 bytes.
[Answer]
# [JavaScript (Node.js)](https://nodejs.org), 47 bytes
```
e=>eval(e.map((a,i)=>(3-i%2*2)*a).join`+`)%10<1
```
Although there is a much shorter answer already, this is my first attempt of golfing in JavaScript so I'd like to hear golfing recommendations :-)
### Testing
```
let f=
e=>eval(e.map((a,i)=>(3-i%2*2)*a).join`+`)%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]));
```
Alternatively, you can **[Try it online!](https://tio.run/##bc9RC4IwEMDx9z5FL8Jmp2xzalL6RSJw2IyJOUnx669T6qEa93g/jv91alFT8zTjHA32pl2v531bOl1WelE90fFDjYQoMLSsSBKZQISChorGnTVDfahpwNmZu11jh8n2Ou7tnbTkIoBBAjkcQYAEdqX09EuSDWSQAkdU@EiOQCCTiHJIfYTB12zkP4ZvORIKDJK@Mxmu@BYjEXp7OYLiTfCin3xqs/X3lbgX "JavaScript (Node.js) – Try It Online")**
[Answer]
# Perl 5, ~~37~~ 32 + 1 (-p) bytes
```
s/./$-+=$&*(--$|*2+1)/ge;$_=/0$/
```
-5 bytes thanks to Dom Hastings.
 37 +1 bytes was
```
$s+=$_*(++$i%2*2+1)for/./g;$_=!!$s%10
```
[try it online](https://tio.run/##LclNCsIwEEDh/ZxjEG1JMz9JJqHkLK6KCMUG69KzGy34lt9ry3ONHV2lue9@8ujGiqfh7By@Bxn54m/LjNfqCX3vQmpZAoEwaSg5gKqlyFIgFU4xKIGZaIgWgbn8RBjoH/BxkmX4bO113x57d239Ag)
[Answer]
# Brainfuck, 228 Bytes
```
>>>>++++[<++>-]<[[>],>>++++++[<++++++++>-]<--[<->-]+[<]>-]>[->]<<<<[[<+>->+<]<[>+>+<<-]>>[<+>-]<<<<<]>>>>[>>[<<[>>+<<-]]>>]<<<++++[<---->-]+++++[<++<+++>>-]<<[<[>>[<<->>-]]>[>>]++[<+++++>-]<<-]<[[+]-<]<++++++[>++[>++++<-]<-]>>+.
```
Can probably be improved a fair bit.
Input is taken 1 digit at a time, outputs 1 for true, 0 for false.
## How it works:
```
>>>>++++[<++>-]<
```
Put 8 at position 3.
```
[[>],>>++++++[<++++++++>-]<--[<->-]+[<]>-]
```
Takes input 8 times, changing it from the ascii value to the actual value +2 each time. Inputs are spaced out by ones, which will be removed, to allow for easier multiplication later.
```
>[->]
```
Subtract one from each item. Our tape now looks something like
```
0 0 0 0 4 0 4 0 8 0 7 0 6 0 2 0 3 0 10 0 0
                                         ^
```
With each value 1 more than it should be. This is because zeros will mess up our multiplication process.
Now we're ready to start multiplying.
```
<<<<
```
Go to the second to last item.
```
[[<+>->+<]<[>+>+<<-]>>[<+>-]<<<<<]
```
While zero, multiply the item it's at by three, then move two items to the left. Now we've multiplied everything we needed to by three, and we're at the very first position on the tape.
```
>>>>[>>[<<[>>+<<-]]>>]
```
Sum the entire list.
```
<<<++++[<---->-]
```
The value we have is 16 more than the actual value. Fix this by subtracting 16.
```
+++++[<++<+++>>-]
```
We need to test whether the sum is a multiple of 10. The maximum sum is with all 9s, which is 144. Since no sum will be greater than 10\*15, put 15 and 10 on the tape, in that order and right to the right of the sum.
```
<<[<[>>[<<->>-]]>[>>]++[<+++++>-]<<-]
```
Move to where 15 is. While it's non-zero, test if the sum is non-zero. If it is, subtract 10 from it. Now we're either on the (empty) sum position, or on the (also empty) ten position. Move one right. If we were on the sum position, we're now on the non-zero 15 position. If so, move right twice. Now we're in the same position in both cases. Add ten to the ten position, and subtract one from the 15 position.
The rest is for output:
```
<[[+]-<]<++++++[>++[>++++<-]<-]>>+.
```
Move to the sum position. If it is non-zero (negative), the barcode is invalid; set the position to -1. Now add 49 to get the correct ascii value: 1 if it's valid, 0 if it's invalid.
[Answer]
# Java 8, 53 bytes
Golfed:
```
b->(3*(b[0]+b[2]+b[4]+b[6])+b[1]+b[3]+b[5]+b[7])%10<1
```
Direct calculation in the lambda appears to the shortest solution. It fits in a single expression, minimizing the lambda overhead and removing extraneous variable declarations and semicolons.
```
public class IsMyBarcodeValid {
  public static void main(String[] args) {
    int[][] barcodes = new int[][] { //
        { 2, 0, 3, 7, 8, 2, 4, 0 }, //
        { 3, 3, 7, 6, 5, 1, 2, 9 }, //
        { 7, 7, 2, 3, 4, 5, 7, 5 }, //
        { 0, 0, 0, 0, 0, 0, 0, 0 }, //
        { 2, 1, 0, 3, 4, 9, 8, 4 }, //
        { 6, 9, 1, 6, 5, 4, 3, 0 }, //
        { 1, 1, 9, 6, 5, 4, 2, 1 }, //
        { 1, 2, 3, 4, 5, 6, 7, 8 } };
    for (int[] barcode : barcodes) {
      boolean result = f(b -> (3 * (b[0] + b[2] + b[4] + b[6]) + b[1] + b[3] + b[5] + b[7]) % 10 < 1, barcode);
      System.out.println(java.util.Arrays.toString(barcode) + " = " + result);
    }
  }
  private static boolean f(java.util.function.Function<int[], Boolean> f, int[] n) {
    return f.apply(n);
  }
}
```
Output:
```
[2, 0, 3, 7, 8, 2, 4, 0] = true
[3, 3, 7, 6, 5, 1, 2, 9] = true
[7, 7, 2, 3, 4, 5, 7, 5] = true
[0, 0, 0, 0, 0, 0, 0, 0] = true
[2, 1, 0, 3, 4, 9, 8, 4] = false
[6, 9, 1, 6, 5, 4, 3, 0] = false
[1, 1, 9, 6, 5, 4, 2, 1] = false
[1, 2, 3, 4, 5, 6, 7, 8] = false
```
[Answer]
# QBasic, ~~54~~ 52 bytes
Ugh, the boring answer turned out to be the shortest:
```
INPUT a,b,c,d,e,f,g,h
?(3*a+b+3*c+d+3*e+f+3*g+h)MOD 10=0
```
This inputs the digits comma-separated. My original 54-byte solution, which inputs one digit at a time, uses a "nicer" approach:
```
m=3
FOR i=1TO 8
INPUT d
s=s+d*m
m=4-m
NEXT
?s MOD 10=0
```
[Answer]
# [C# (.NET Core)](https://www.microsoft.com/net/core/platform), 65 62 bytes
```
b=>{int s=0,i=0,t=1;while(i<8)s+=b[i++]*(t^=2);return s%10<1;}
```
[Try it online!](https://tio.run/##jZHBaoQwEIbPzVPMpaA1LcZ1XSVmL6U9tVDooQexoG7YBmwCJnYp4rNbzVbYQ6GB5DAz@eaff9Lo20Z1fOq1kEd4/daGf1LUtJXW8DIgbSojGnjsZZMLaYoSQ61Uu4eHSqbAYKrZfpgLoFmIxXwNI/T0IVruiTz1dcDqQgRBeeOZdxb5tOOm7yToaxLmhI4TRavElxIHeK6E9Hw0oKt7JbVq@d1bJwx/EpJ7i6In@akoYYAIQ4hhg2GHIcVLGM8ZGH2f/stuVjDBsMVALJ65sTsLRrZDbPE53LqxIf7r/LIujslqelbOrO/YTTmx78nqOLZNHLdFLJhdsMskzuzlqpLzd53ZEY3TDw "C# (.NET Core) – Try It Online")
### Acknowledgements
-3 bytes thanks to @KevinCruijssen and the neat trick using the exclusive-or operator.
### DeGolfed
```
b=>{
    int s=0,i=0,t=1;
    while(i<8)
        s+=b[i++]*(t^=2); // exclusive-or operator alternates t between 3 and 1.
    return s%10<1;
}
```
# [C# (.NET Core)](https://www.microsoft.com/net/core/platform), 53 bytes
```
b=>(3*(b[0]+b[2]+b[4]+b[6])+b[1]+b[3]+b[5]+b[7])%10<1
```
[Try it online!](https://tio.run/##jZFBS8QwEIXP5lfMRUg0StOm7Zbu7kX0pCB48FByaGOQQE1g01Wk9LfXJmthD4KB8MiEfG/yJtLdSHtQ89Fp8w4v325QHzWSfescPI/IDe2gJTwcjdxqMzSCQmdtv4f71mxgB3O32@PsCndNIq67JvXCvRSCLMr8NvOSeykFuWTJls01Wp0/rX6Dp1YbTNCILu6scbZXt68HPahHbRT2jbBRX42AEVIKCYWMQklhQ33JlxOYCKn/ZbMVLCjkFFjAqzi2DGAaHHjAlzKPYxP61/plYxKzNfTSuQq5eVznItxna2IeTCKnxQJYnbH@JdHs@aiK03ed2AlN8w8 "C# (.NET Core) – Try It Online")
A direct port of [@Snowman's answer](https://codegolf.stackexchange.com/a/148366).
[Answer]
# [K (oK)](https://github.com/JohnEarnest/ok), ~~16~~ 15 bytes
**Solution:**
```
{~10!+/x*8#3 1}
```
[Try it online!](https://tio.run/##y9bNz/7/v7rO0EBRW79Cy0LZWMGw1kjBQMFYwVzBQsFIwUTB4P9/AA "K (oK) – Try It Online")
**Examples:**
```
{~10!+/x*8#3 1}2 1 0 3 4 9 8 5
1
{~10!+/x*8#3 1}2 1 0 3 4 9 8 4
0
{~10!+/x*8#3 1}2 0 3 7 8 2 4 0
1
```
**Explanation:**
K is interpreted right-to-left:
```
{~10!+/x*8#3 1} / the solution
{             } / lambda with x as implicit input
           3 1  / the list [3,1]
         8#     / 8 take this list = [3,1,3,1,3,1,3,1]
       x*       / multiply input by this
     +/         / sum over the list
  10!           / 10 mod this sum
 ~              / not, 0 => 1, anything else => 0
```
[Answer]
# [Vyxal](https://github.com/Lyxal/Vyxal), 8 bytes
```
y$3*J∑₀Ḋ
```
[Try it Online!](http://lyxal.pythonanywhere.com?flags=&code=y%243*J%E2%88%91%E2%82%80%E1%B8%8A&inputs=%5B2%2C0%2C3%2C7%2C8%2C2%2C4%2C0%5D&header=&footer=)
```
y        # Uninterleave
 $       # Swap
  3*     # Multiply by 3 (vectorised)
    J    # Join
     ∑   # Sum
      ₀Ḋ # Is divisible by 10?
```
[Answer]
# MATLAB/[Octave](https://www.gnu.org/software/octave/), 32 bytes
```
@(x)~mod(sum([2*x(1:2:7),x]),10)
```
[Try it online!](https://tio.run/##Vc7LDsIgEAXQvV/CmBsClII0MfE/TBdG7a7pwkdY@et4hXZhZjVnnsv1eXnfy3TUWpeTyvKZl5t6vGZ1dvus7OCGKMijwBopExUGHSIOcPAwo@yIXaWAHpacGkaSY8GTI/qGBn/R0HHM1M7Evb5hYGLrTs/S2mlJaUVObbidCb/HRilf "Octave – Try It Online")
I'm going to post this despite the other Octave answer as I developed this code and approach without looking at the other answers.
Here we have an anonymous function which takes the input as an array of 8 values, and return true if a valid barcode, false otherwise..
The result is calculated as follows.
```
              2*x(1:2:7)
             [          ,x]
         sum(              )
     mod(                   ,10)
@(x)~
```
1. Odd digits (one indexed) are multiplied by 2.
2. The result is prepended to the input array, giving an array whose sum will contain the odd digits three times, and the even digits once.
3. We do the sum which will also include the supplied checksum within our sum.
4. Next the modulo 10 is performed. If the checksum supplied was valid, the sum of all multiplied digits including the checksum value would end up being a multiple of 10. Therefore only a valid barcode would return 0.
5. The result is inverted to get a logical output of true if valid.
[Answer]
# Excel, 37 bytes
Interpreting "A list of 8 integers" as allowing 8 separate cells in Excel:
```
=MOD(SUM(A1:H1)+2*(A1+C1+E1+G1),10)=0
```
]