g | x | w | all
Bytes Lang Time Link
034TIBASIC TI83 Plus250523T172801Zmadeforl
069Tcl250123T172203Zsergiol
060CASIO BASIC CASIO fx9750GIII250204T200014Zmadeforl
011Japt h240607T001110ZShaggy
040250123T053242ZUsed_Bra
041Haskell241205T181642Zmatteo_c
034Perl 5 MListUtil=sum pl241205T165258ZXcali
036AWK241205T153527Zxrs
092Common Lisp240609T085909ZPaul Ric
024R240607T194936Zpajonk
008Jelly240608T154145ZJonathan
047Python 3.8240607T014259ZJonathan
029TIBASIC240608T110019ZSylveste
040JavaScript ES6240606T173719ZArnauld
058Google Sheets240608T023550Zz..
015J240608T004757Zsouth
031Wolfram Language Mathematica240607T230203ZGreg Mar
016Charcoal240607T222102ZNeil
042Arturo240607T175246Zchunes
042Python240607T135124ZAlbert.L
00805AB1E240607T080842ZKevin Cr
008Nekomata + e240607T015744Zalephalp
017K ngn/k240607T020509Zakamayu
040JavaScript Node.js240607T014800Zl4m2
043PowerShell Core240606T215038ZJulian
011MATL240606T210345ZLuis Men
051C gcc240606T221708ZAZTECCO
023APL+WIN240606T213104ZGraham
016Uiua SBCS240606T205309Zchunes
060Python 3240606T194540Zcorvus_1

TI-BASIC (TI-83 Plus), 34 bytes

input as a list

Input A
ʟAcumSum(binomcdf(7,0
ʟA(8)=11fPart(11⁻¹sum(ΔList(cumSum(Ans)-Ans

based off of sylvester's answer in TI-BASIC (TI-84 Plus CE)

explanation

:Input A                                        get input, set it to ʟA
:ʟAcumSum(binomcdf(7,0                          multiply list by its weight, set to Ans
                      ΔList(cumSum(Ans)-Ans     remove last element in Ans
                  sum(                          sum Ans together
       11fPart(11⁻¹                              modulo Ans by 11
:ʟA(8)=                                         compare it to the check digit and output truthy or falsy

Tcl, 69 bytes

proc P n {expr ([lmap c [split $n ""] {list +[incr i]%8*$c}])%11==$c}

Try it online!

CASIO BASIC (CASIO fx-9750GIII), 60 bytes

?→Str 1
0
For 1→N To StrLen(Str 1)-1
Ans+NExp(StrMid(Str 1,N,1))
Next
Ans Rmdr 11=Exp(StrRight(Str 1,1))

outputs 1 or 0 if its valid or not (respectively)

Japt -h, 11 bytes

ǶUxÈ*°YÃuB

Try it

ǶUxÈ*°YÃuB     :Implcit input of digit array U
Ç               :Modify last element
 ¶              :  Is it equal to
  Ux            :    The remaining elements of U reduced by addition after
    È           :    Passing each, at 0-based index Y, through the following function
     *          :      Multiply by
      °Y        :      Prefix incremented Y
        Ã       :    End reduce
         u      :    Modulo
          B     :    11
                :Implicit output of last element

☾, 18 17 15 chars (46 47 40 bytes)

code with custom font

󷺹ᴙ󷹝Ϝ􍨅+⨁⟞󷹝₇2∣ᵜ11
(Note: ☾ uses a custom font, you can copy-paste the above code into the Web UI)

explanation

Since ascii values are 48 off of their numerical counterpart, the difficulty here is keeping track of what initial value for the accumulate will counteract the continuum of 48's that arise in the list. We initialize the sum with 2 of the check number because the accumulate will give us 8 copies, so to get back to -1 mod 11, we add 2 more copies.

Haskell, 41 bytes

f x=mod(x!!7*2+sum(zipWith(*)[1..]x))11<1

Attempt This Online!

Perl 5 -MList::Util=sum -pl, 34 bytes

$_=(pop@F)==(sum map$_*++$i,@F)%11

Try it online!

AWK, 36 bytes

{for(;++i<NF;)s+=$i*++x}$0=s%11==$NF

Attempt This Online!

{for(;++i<NF;) # each digit
s+=            # sum
$i*++x}        # digit times location
$0=            # set output
s%11==$NF      # sum mod 11 = last digit

Prints 1 if valid or nothing.

Common Lisp, 92 bytes

Input is a list of numbers

(defun p(n)(=(mod(reduce'+(mapcar(lambda(x y)(* x y))n'(1 2 3 4 5 6 7 0)))11)(car(last n))))

R, 28 24 bytes

\(d)sum(d*c(1:7,-1))%%11

Attempt This Online!

Takes input as a vector of digits. Outputs swapped truthy (non-zero) / falsy (zero).

Jelly, 8 bytes

ṖḋJ%11⁼Ṫ

A monadic Link that accepts the list of eight digits and yields 1 (truthy) if a valid PZN or 0 (falsey) otherwise.

Try it online! Or see the test-suite.

How?

Direct implementation of the specification.

ṖḋJ%11⁼Ṫ - Link: list of eight digits, A = [a,b,c,d,e,f,g,h]
Ṗ        - pop {A} -> P = [a,b,c,d,e,f,g]
  J      - indices {A} -> I = [1,2,3,4,5,6,7,8]
 ḋ       - {P} dot product {I} -> S = 1×a+2×b+3×c+4×d+5×e+6×f+7×g+8×0
   %11   - {S} mod 11
       Ṫ - tail {A} -> h
      ⁼  - {S mod 11} equals {h}?

Python 3.8,  50  47 bytes

-1 thanks to l4m2* leading to two more.

Could save at least two bytes by outputting a falsey value for valid and a truthy value for invalid; potentially quite a few using a recursive function.

lambda d,i=0:sum(v*(i:=i+5)for v in d)%11==d[7]

An unnamed function that accepts the list of digits and returns True or False.

Try it online!

How?

Call the weighted sum of the first seven digits \$S\$ and the final digit \$h\$.

A PZN is valid iff \$S \equiv h \mod 11\$

We want an equivalent condition using all eight digits in the sum, i.e. \$S+8h\$, so we can do

for v in d

rather than

for v in d[:7]

So we find \$m\$ such that \$m(S+8h) \equiv h \mod 11\$.

Substituting in \$S \equiv h \mod 11\$ we have \$m(h+8h) \equiv h \mod 11\$, so \$9mh \equiv h \mod 11\$ thus \$9m \equiv 1 \mod 11\$, which is satisfied by \$m=5\$ since \$45 \equiv 1 \mod 11\$.

This gives us

lambda d,i=0:sum(v*(i:=i+1)for v in d)*5%11==d[7]

For 49 bytes, as suggested by l4m2.

Now we can move the multiplication inside our weighted sum to give the code at the top.


My original 50 byte answer

lambda d,i=0:sum(v*(i:=i+1)+3*d[7]for v in d)%11<1

An unnamed function that accepts the list of digits and returns True or False.

Try it online!

Note that \$8\times 3 + 8 = 32 \equiv -1 \mod 11 \$


* arnauld also made a fairly trivial 49er that avoids much real trickery (just make the right multiplier for each digit!):

lambda d,i=1:sum(v*~-((i:=i+1)%9)for v in d)%11<1

TI-BASIC, 29 bytes

Input A
ʟA(8)=remainder(Σ(IʟA(I),I,1,7),11

This program takes an array of digits as inputs, and outputs 1 (for true) or 0 (for false). It uses a summation to multiply the digits by their weights and add them together. It then checks if the result modulo eleven is equal to the last digit.

Example input and output:

Example input and output for both true and false results.

JavaScript (ES6), 40 bytes

Expects an array of 8 digits and returns a Boolean value.

a=>!a.reduce(p=>p%11+a[i++]*~(~i%9),i=0)

Try it online!

Commented

a =>           // a[] = input array
!a.reduce(p => // for each value in a[] with accumulator p:
  p % 11 +     //   reduce p modulo 11
  a[i++] *     //   add the next value from a[] multiplied by
  ~(~i % 9),   //   1 .. 7 for the first 7 elements
               //   or -1 for the last one
  i = 0        //   starting with p = 0 and i = 0
)              // end of reduce() -> turned into a Boolean

Google Sheets, 58 bytes

=SORT(MOD(A1,10)=MOD(SUM(MID(A1,ROW(1:7),1)*ROW(1:7)),11))

J, 15 bytes

{:=11|1#.7$[*#\

Attempt This Online!

{:=11|1#.7$[*#\
             #\   NB. 1,2,3,...,8
            *     NB. multiplication
           [      NB. input digit array
         7$       NB. first 7 digits
      1#.         NB. sum
   11|            NB. mod 11
  =               NB. equals
{:                NB. last digit of input

Wolfram Language (Mathematica), 31 bytes

Mod[Most@#.Range@7,11]==Last@#&

Try all test cases online! Unnamed function taking a list of eight digits as input and returning True or False.

Charcoal, 16 bytes

⁼﹪Σ⭆…θ⁷×ι⊕κ¹¹﹪Nχ

Try it online! Takes input as a string and outputs a Charcoal boolean, i.e. - for a valid PZN, nothing if not. Explanation:

     θ              Input string
    …               Truncated to length
      ⁷             Literal integer `7`
   ⭆                Map over characters and join
        ι           Current character
       ×            Repeated by
          κ         Current index
         ⊕          Incremented
  Σ                 Take the digital sum
 ﹪                  Modulo
           ¹¹       Literal integer `11`
⁼                   Is equal to
              N     Input as a number
             ﹪      Modulo
               χ    Predefined variable `10`
                    Implicitly print

13 bytes by taking input as an array of integers:

⁼⊟θ﹪ΣEθ×ι⊕κ¹¹

Try it online! Link is to verbose version of code. Explanation:

  θ             Input array
 ⊟              Remove last element
⁼               Equals
      θ         Remainder of input array
     E          Map over elements
        ι       Current element
       ×        Multiplied by
          κ     Current index
         ⊕      Incremented
    Σ           Take the sum
   ﹪            Modulo
           ¹¹   Literal integer `11`
                Implicitly print

Arturo, 42 bytes

$->a[0x:∑map a\[0..6]=>[&*<=1+]a\7=x%11]

Try it!

Explanation

$->a[]            ; a function taking a list a
0                 ; push zero, our multiplier, to stack
x:                ; let x be...
∑                 ; sum of...
map a\[0..6]=>[]  ; first seven numbers of input mapped to...
&                 ; current digit...
*                 ; multiplied by...
<=                ; extra copy of...
1+                ; top of stack plus one
a\7=              ; is the last number of input equal to...
x%11              ; x modulo eleven?

Python, 42 bytes

lambda d:int(d[6::-1].hex())//.99%11==d[7]

Attempt This Online!

Expects input as a byte string.

How?

This abuses the hex method of bytes objects to implement a poor man's base 100 conversion. The old divide by base-1 trick is then used to get partial sums over the digits (we had to reverse their order for this to come out right). To get the sum over digits we would normally have done mod 99 but as we have to do mod 11 in the end anyway we can save it here.

05AB1E, 8 bytes

¨ƶO11%Qθ

Input as a list of digits.

Try it online or verify all test cases.

Explanation:

¨         # Remove the last digit of the (implicit) input-list
 ƶ        # Multiply each value by their 1-based index
  O       # Sum
   11%    # Modulo-11
      Q   # Check for each digit in the (implicit) input-list whether it equals this
       θ  # Pop and only leave the last check
          # (which is output implicitly as result)

Nekomata + -e, 8 bytes

7R¢ɔ∙11¦

Attempt This Online!

7R¢ɔ∙11¦
7R          [1, 2, 3, 4, 5, 6, 7]
  ¢ɔ        Append 10
    ∙       Dot product with the input
     11¦    Check if the result is divisible by 11

K (ngn/k), 17 bytes

It takes a digit array.

{*|x=11!+/1+&7#x}
             7#x     First 7 digits
          1+&        a b c d ... ->  1 for a times, 2 for b times, ...
        +/           Inner product between first 7 digits and 1 2 3 4 5 6 7
     11!             Mod 11
 *|x=                Same as the last digit?               

Try it online!

JavaScript (Node.js), 40 bytes

a=>1>a.reduce((p,v,i)=>p-~i*v,a[7]*2)%11

Try it online!

From Arnauld's. 8th digit * 8 + 8th digit * 2 = 8th digit * (-1), modulo 11

PowerShell Core, 43 bytes

$args[0..6]|%{$s+=$_*++$i}
$s%11-eq$args[7]

Try it online!

MATL, 12 11 bytes

0&)7:*s11\=

Try it online! Or verify all test cases.

Explanation

       % Implicit input: numeric vector
0&)    % 2-output indexing (modular, 1-based) with 0: pushes the last element,
       % then a vector with the remaining elements
7:     % Push [1 2 ... 7]
*      % Multiply, element-wise
s      % Sum
11\    % Modulo 11
=      % Equal?
       % Implicit display

C (gcc), 51 bytes

s,i;f(int*l){for(i=s=0;i<7;)s+=*l++*++i;s=s%11-*l;}

Try it online!

function returning true if invalid, false if valid PZN code.

APL+WIN, 23 bytes

Prompts for number as a string of digits.

(7↓n)=11|+/(⍳7)×7↑n←⍎¨⎕

Try it online! Thanks to Dyalog Classic

Uiua SBCS, 16 bytes

=◿11/+×⇌¯⇡¯7:°⊂⇌

Try it!

Python 3, 60 bytes

lambda a:sum([x*-~i for i,x in enumerate(a[:-1])])%11==a[-1]

Try it online!