Jump to content

ISBN13 check digit: Difference between revisions

→‎{{header|Excel}}: Added an Excel LAMBDA version.
(Add PL/M)
(→‎{{header|Excel}}: Added an Excel LAMBDA version.)
Line 1,010:
assert(!isValidISBN13("978-1788399083"));
}</lang>
 
=={{header|Excel}}==
===LAMBDA===
 
Binding the name '''ISBN13Check''' to the following lambda expression in the Name Manager of the Excel WorkBook:
 
(See [https://www.microsoft.com/en-us/research/blog/lambda-the-ultimatae-excel-worksheet-function/ LAMBDA: The ultimate Excel worksheet function])
 
{{Works with|Office 365 betas 2021}}
<lang lisp>ISBN13Check
=LAMBDA(s,
LET(
ns, FILTERP(
LAMBDA(v,
NOT(ISERROR(v))
)
)(
VALUE(CHARSROW(s))
),
ixs, SEQUENCE(
1, COLUMNS(ns),
1, 1
),
 
0 = MOD(
SUM(
IF(0 <> MOD(ixs, 2),
INDEX(ns, ixs),
3 * INDEX(ns, ixs)
)
),
10
)
)
)</lang>
 
and also assuming the following generic bindings in the Name Manager for the WorkBook:
 
<lang lisp>CHARSROW
=LAMBDA(s,
MID(s,
SEQUENCE(1, LEN(s), 1, 1),
1
)
)
 
 
FILTERP
=LAMBDA(p,
LAMBDA(xs,
FILTER(xs, p(xs))
)
)
 
 
ISDIGIT
=LAMBDA(c,
LET(
ic, CODE(c),
 
AND(47 < ic, 58 > ic)
)
)</lang>
 
{{Out}}
{| class="wikitable"
|-
|||style="text-align:right; font-family:serif; font-style:italic; font-size:120%;"|fx
! colspan="2" style="text-align:left; vertical-align: bottom; font-family:Arial, Helvetica, sans-serif !important;"|=ISBN13Check(A2)
|- style="text-align:center; font-family:Arial, Helvetica, sans-serif !important; background-color:#000000; color:#ffffff;"
|
| A
| B
|-
| style="text-align:center; font-family:Arial, Helvetica, sans-serif !important; background-color:#000000; color:#ffffff" | 1
| style="font-weight:bold" | Candidate string
| style="font-weight:bold" | ISBN13 checked
|-
| style="text-align:center; font-family:Arial, Helvetica, sans-serif !important; background-color:#000000; color:#ffffff" | 2
| 978-1734314502
| style="background-color:#cbcefb" | TRUE
|-
| style="text-align:center; font-family:Arial, Helvetica, sans-serif !important; background-color:#000000; color:#ffffff" | 3
| 978-1734314509
| FALSE
|-
| style="text-align:center; font-family:Arial, Helvetica, sans-serif !important; background-color:#000000; color:#ffffff" | 4
| 978-1788399081
| TRUE
|-
| style="text-align:center; font-family:Arial, Helvetica, sans-serif !important; background-color:#000000; color:#ffffff" | 5
| 978-1788399083
| FALSE
|}
 
 
=={{header|Factor}}==
9,659

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.