ISBN13 check digit: Difference between revisions

Content added Content deleted
(for clarity, replaced ISBN for opCode with ISBN for Python Interviews (which I have no vested interest in))
Line 34: Line 34:
R product % 10 == 0
R product % 10 == 0


V tests = |‘978-1734314502
V tests = |‘978-0596528126
978-1734314509
978-0596528120
978-1788399081
978-1788399081
978-1788399083’.split("\n")
978-1788399083’.split("\n")
Line 44: Line 44:
{{out}}
{{out}}
<pre>
<pre>
ISBN13 978-1734314502 validates 1B
ISBN13 978-0596528126 validates 1B
ISBN13 978-1734314509 validates 0B
ISBN13 978-0596528120 validates 0B
ISBN13 978-1788399081 validates 1B
ISBN13 978-1788399081 validates 1B
ISBN13 978-1788399083 validates 0B
ISBN13 978-1788399083 validates 0B
Line 122: Line 122:
{{out}}
{{out}}


<pre>A>isbn13 978-1734314502
<pre>A>isbn13 978-0596528126
good
good
A>isbn13 978-1734314509
A>isbn13 978-0596528120
bad
bad
A>isbn13 978-1788399081
A>isbn13 978-1788399081
Line 190: Line 190:
{{out}}
{{out}}


<pre>C:\>isbn13 978-1734314502
<pre>C:\>isbn13 978-0596528126
good
good
C:\>isbn13 978-1734314509
C:\>isbn13 978-0596528120
bad
bad
C:\>isbn13 978-1788399081
C:\>isbn13 978-1788399081
Line 241: Line 241:
Put(125) PutE() ;clear screen
Put(125) PutE() ;clear screen


Test("978-1734314502")
Test("978-0596528126")
Test("978-1734314509")
Test("978-0596528120")
Test("978-1788399081")
Test("978-1788399081")
Test("978-1788399083")
Test("978-1788399083")
Line 249: Line 249:
[https://gitlab.com/amarok8bit/action-rosetta-code/-/raw/master/images/ISBN13_check_digit.png Screenshot from Atari 8-bit computer]
[https://gitlab.com/amarok8bit/action-rosetta-code/-/raw/master/images/ISBN13_check_digit.png Screenshot from Atari 8-bit computer]
<pre>
<pre>
978-1734314502 is correct
978-0596528126 is correct
978-1734314509 is incorrect
978-0596528120 is incorrect
978-1788399081 is correct
978-1788399081 is correct
978-1788399083 is incorrect
978-1788399083 is incorrect
Line 288: Line 288:
end Show;
end Show;
begin
begin
Show ("978-1734314502");
Show ("978-0596528126");
Show ("978-1734314509");
Show ("978-0596528120");
Show ("978-1788399081");
Show ("978-1788399081");
Show ("978-1788399083");
Show ("978-1788399083");
end ISBN_Check;</syntaxhighlight>
end ISBN_Check;</syntaxhighlight>
{{out}}
{{out}}
<pre>978-1734314502 Good
<pre>978-0596528126 Good
978-1734314509 Bad
978-0596528120 Bad
978-1788399081 Good
978-1788399081 Good
978-1788399083 Bad</pre>
978-1788399083 Bad</pre>
Line 323: Line 323:
END; # check isbn13 #
END; # check isbn13 #
# task test cases #
# task test cases #
[]STRING tests = ( "978-1734314502", "978-1734314509", "978-1788399081", "978-1788399083" );
[]STRING tests = ( "978-0596528126", "978-0596528120", "978-1788399081", "978-1788399083" );
[]BOOL expected = ( TRUE, FALSE, TRUE, FALSE );
[]BOOL expected = ( TRUE, FALSE, TRUE, FALSE );
FOR pos FROM LWB tests TO UPB tests DO
FOR pos FROM LWB tests TO UPB tests DO
Line 338: Line 338:
{{out}}
{{out}}
<pre>
<pre>
978-1734314502: good
978-0596528126: good
978-1734314509: bad
978-0596528120: bad
978-1788399081: good
978-1788399081: good
978-1788399083: bad
978-1788399083: bad
Line 353: Line 353:
{{out}}
{{out}}


<pre> check_isbn13¨ '978-1734314502' '978-1734314509' '978-1788399081' '978-1788399083'
<pre> check_isbn13¨ '978-0596528126' '978-0596528120' '978-1788399081' '978-1788399083'
1 0 1 0</pre>
1 0 1 0</pre>


Line 388: Line 388:
end script
end script
map(test, {"978-1734314502", "978-1734314509", ¬
map(test, {"978-0596528126", "978-0596528120", ¬
"978-1788399081", "978-1788399083"})
"978-1788399081", "978-1788399083"})
end run
end run
Line 565: Line 565:
end zipWith</syntaxhighlight>
end zipWith</syntaxhighlight>
{{Out}}
{{Out}}
<pre>{{"978-1734314502", true}, {"978-1734314509", false}, {"978-1788399081", true}, {"978-1788399083", false}}</pre>
<pre>{{"978-0596528126", true}, {"978-0596528120", false}, {"978-1788399081", true}, {"978-1788399083", false}}</pre>


===Straightforward===
===Straightforward===
Line 599: Line 599:
set output to {}
set output to {}
set verdicts to {"bad", "good"}
set verdicts to {"bad", "good"}
repeat with thisISBN13 in {"978-1734314502", "978-1734314509", "978-1788399081", "978-1788399083"}
repeat with thisISBN13 in {"978-0596528126", "978-0596528120", "978-1788399081", "978-1788399083"}
set isValid to validateISBN13(thisISBN13)
set isValid to validateISBN13(thisISBN13)
set end of output to thisISBN13 & ": " & item ((isValid as integer) + 1) of verdicts
set end of output to thisISBN13 & ": " & item ((isValid as integer) + 1) of verdicts
Line 611: Line 611:


{{output}}
{{output}}
<pre>"978-1734314502: good
<pre>"978-0596528126: good
978-1734314509: bad
978-0596528120: bad
978-1788399081: good
978-1788399081: good
978-1788399083: bad"</pre>
978-1788399083: bad"</pre>
Line 660: Line 660:


tests: [
tests: [
"978-1734314502" "978-1734314509"
"978-0596528126" "978-0596528120"
"978-1788399081" "978-1788399083"
"978-1788399081" "978-1788399083"
]
]
Line 670: Line 670:
{{out}}
{{out}}


<pre>978-1734314502 => true
<pre>978-0596528126 => true
978-1734314509 => false
978-0596528120 => false
978-1788399081 => true
978-1788399081 => true
978-1788399083 => false</pre>
978-1788399083 => false</pre>
Line 682: Line 682:
}</syntaxhighlight>
}</syntaxhighlight>
Examples:<syntaxhighlight lang="autohotkey">output := ""
Examples:<syntaxhighlight lang="autohotkey">output := ""
nums := ["978-1734314502","978-1734314509","978-1788399081","978-1788399083"]
nums := ["978-0596528126","978-0596528120","978-1788399081","978-1788399083"]
for i, n in nums
for i, n in nums
output .= ISBN13_check_digit(n) "`n"
output .= ISBN13_check_digit(n) "`n"
Line 688: Line 688:
return</syntaxhighlight>
return</syntaxhighlight>
{{out}}
{{out}}
<pre>978-1734314502 (good)
<pre>978-0596528126 (good)
978-1734314509 (bad)
978-0596528120 (bad)
978-1788399081 (good)
978-1788399081 (good)
978-1788399083 (bad)</pre>
978-1788399083 (bad)</pre>
Line 697: Line 697:
# syntax: GAWK -f ISBN13_CHECK_DIGIT.AWK
# syntax: GAWK -f ISBN13_CHECK_DIGIT.AWK
BEGIN {
BEGIN {
arr[++n] = "978-1734314502"
arr[++n] = "978-0596528126"
arr[++n] = "978-1734314509"
arr[++n] = "978-0596528120"
arr[++n] = "978-1788399081"
arr[++n] = "978-1788399081"
arr[++n] = "978-1788399083"
arr[++n] = "978-1788399083"
Line 720: Line 720:
{{out}}
{{out}}
<pre>
<pre>
978-1734314502 OK
978-0596528126 OK
978-1734314509 NG check digit S/B 2
978-0596528120 NG check digit S/B 2
978-1788399081 OK
978-1788399081 OK
978-1788399083 NG check digit S/B 1
978-1788399083 NG check digit S/B 1
Line 731: Line 731:
{{trans|Ring}}
{{trans|Ring}}
<syntaxhighlight lang="vb">arraybase 1
<syntaxhighlight lang="vb">arraybase 1
dim isbn = {"978-1734314502", "978-1734314509", "978-1788399081", "978-1788399083", "978-2-74839-908-0", "978-2-74839-908-5", "978 1 86197 876 9"}
dim isbn = {"978-0596528126", "978-0596528120", "978-1788399081", "978-1788399083", "978-2-74839-908-0", "978-2-74839-908-5", "978 1 86197 876 9"}


for n = 1 to isbn[?]
for n = 1 to isbn[?]
Line 782: Line 782:


let start() be
let start() be
$( show("978-1734314502")
$( show("978-0596528126")
show("978-1734314509")
show("978-0596528120")
show("978-1788399081")
show("978-1788399081")
show("978-1788399083")
show("978-1788399083")
$)</syntaxhighlight>
$)</syntaxhighlight>
{{out}}
{{out}}
<pre>978-1734314502: good
<pre>978-0596528126: good
978-1734314509: bad
978-0596528120: bad
978-1788399081: good
978-1788399081: good
978-1788399083: bad</pre>
978-1788399083: bad</pre>
Line 820: Line 820:
int main() {
int main() {
int i;
int i;
const char* isbns[] = {"978-1734314502", "978-1734314509", "978-1788399081", "978-1788399083"};
const char* isbns[] = {"978-0596528126", "978-0596528120", "978-1788399081", "978-1788399083"};
for (i = 0; i < 4; ++i) {
for (i = 0; i < 4; ++i) {
printf("%s: %s\n", isbns[i], check_isbn13(isbns[i]) ? "good" : "bad");
printf("%s: %s\n", isbns[i], check_isbn13(isbns[i]) ? "good" : "bad");
Line 829: Line 829:
{{out}}
{{out}}
<pre>
<pre>
978-1734314502: good
978-0596528126: good
978-1734314509: bad
978-0596528120: bad
978-1788399081: good
978-1788399081: good
978-1788399083: bad
978-1788399083: bad
Line 866: Line 866:


int main() {
int main() {
auto isbns = { "978-1734314502", "978-1734314509", "978-1788399081", "978-1788399083" };
auto isbns = { "978-0596528126", "978-0596528120", "978-1788399081", "978-1788399083" };
for (auto isbn : isbns) {
for (auto isbn : isbns) {
std::cout << isbn << ": " << (check_isbn13(isbn) ? "good" : "bad") << '\n';
std::cout << isbn << ": " << (check_isbn13(isbn) ? "good" : "bad") << '\n';
Line 874: Line 874:
}</syntaxhighlight>
}</syntaxhighlight>
{{out}}
{{out}}
<pre>978-1734314502: good
<pre>978-0596528126: good
978-1734314509: bad
978-0596528120: bad
978-1788399081: good
978-1788399081: good
978-1788399083: bad</pre>
978-1788399083: bad</pre>
Line 886: Line 886:
{
{
public static void Main() {
public static void Main() {
Console.WriteLine(CheckISBN13("978-1734314502"));
Console.WriteLine(CheckISBN13("978-0596528126"));
Console.WriteLine(CheckISBN13("978-1734314509"));
Console.WriteLine(CheckISBN13("978-0596528120"));
Console.WriteLine(CheckISBN13("978-1788399081"));
Console.WriteLine(CheckISBN13("978-1788399081"));
Console.WriteLine(CheckISBN13("978-1788399083"));
Console.WriteLine(CheckISBN13("978-1788399083"));
Line 931: Line 931:
po: stream := stream$primary_output()
po: stream := stream$primary_output()
tests: array[string] := array[string]$
tests: array[string] := array[string]$
["978-1734314502",
["978-0596528126",
"978-1734314509",
"978-0596528120",
"978-1788399081",
"978-1788399081",
"978-1788399083"]
"978-1788399083"]
Line 946: Line 946:
end start_up</syntaxhighlight>
end start_up</syntaxhighlight>
{{out}}
{{out}}
<pre>978-1734314502: good
<pre>978-0596528126: good
978-1734314509: bad
978-0596528120: bad
978-1788399081: good
978-1788399081: good
978-1788399083: bad</pre>
978-1788399083: bad</pre>
Line 980: Line 980:
01 IX PIC S9(4) COMP.
01 IX PIC S9(4) COMP.
01 TEST-ISBNS.
01 TEST-ISBNS.
02 FILLER PIC X(14) VALUE '978-1734314502'.
02 FILLER PIC X(14) VALUE '978-0596528126'.
02 FILLER PIC X(14) VALUE '978-1734314509'.
02 FILLER PIC X(14) VALUE '978-0596528120'.
02 FILLER PIC X(14) VALUE '978-1788399081'.
02 FILLER PIC X(14) VALUE '978-1788399081'.
02 FILLER PIC X(14) VALUE '978-1788399083'.
02 FILLER PIC X(14) VALUE '978-1788399083'.
Line 1,096: Line 1,096:
{{out}}
{{out}}


<pre>978-1734314502 (good)
<pre>978-0596528126 (good)
978-1734314509 (bad)
978-0596528120 (bad)
978-1788399081 (good)
978-1788399081 (good)
978-1788399083 (bad)
978-1788399083 (bad)
Line 1,129: Line 1,129:
var isbns: [uint8][] := {
var isbns: [uint8][] := {
"978-1734314502", "978-1734314509", "978-1788399081", "978-1788399083"
"978-0596528126", "978-0596528120", "978-1788399081", "978-1788399083"
};
};
Line 1,141: Line 1,141:
end loop;</syntaxhighlight>
end loop;</syntaxhighlight>
{{out}}
{{out}}
<pre>978-1734314502: good
<pre>978-0596528126: good
978-1734314509: bad
978-0596528120: bad
978-1788399081: good
978-1788399081: good
978-1788399083: bad</pre>
978-1788399083: bad</pre>
Line 1,168: Line 1,168:


unittest {
unittest {
assert(isValidISBN13("978-1734314502"));
assert(isValidISBN13("978-0596528126"));
assert(!isValidISBN13("978-1734314509"));
assert(!isValidISBN13("978-0596528120"));
assert(isValidISBN13("978-1788399081"));
assert(isValidISBN13("978-1788399081"));
assert(!isValidISBN13("978-1788399083"));
assert(!isValidISBN13("978-1788399083"));
Line 1,266: Line 1,266:


proc nonrec main() void:
proc nonrec main() void:
test("978-1734314502");
test("978-0596528126");
test("978-1734314509");
test("978-0596528120");
test("978-1788399081");
test("978-1788399081");
test("978-1788399083")
test("978-1788399083")
corp</syntaxhighlight>
corp</syntaxhighlight>
{{out}}
{{out}}
<pre>978-1734314502: good
<pre>978-0596528126: good
978-1734314509: bad
978-0596528120: bad
978-1788399081: good
978-1788399081: good
978-1788399083: bad</pre>
978-1788399083: bad</pre>
Line 1,390: Line 1,390:
|-
|-
| style="text-align:center; font-family:Arial, Helvetica, sans-serif !important; background-color:#000000; color:#ffffff" | 2
| style="text-align:center; font-family:Arial, Helvetica, sans-serif !important; background-color:#000000; color:#ffffff" | 2
| 978-1734314502
| 978-0596528126
| style="background-color:#cbcefb" | TRUE
| style="background-color:#cbcefb" | TRUE
|-
|-
| style="text-align:center; font-family:Arial, Helvetica, sans-serif !important; background-color:#000000; color:#ffffff" | 3
| style="text-align:center; font-family:Arial, Helvetica, sans-serif !important; background-color:#000000; color:#ffffff" | 3
| 978-1734314509
| 978-0596528120
| FALSE
| FALSE
|-
|-
Line 1,419: Line 1,419:
{ [ length 13 = ] [ [ digit? ] all? ] [ (isbn13?) ] } 1&& ;
{ [ length 13 = ] [ [ digit? ] all? ] [ (isbn13?) ] } 1&& ;


qw{ 978-1734314502 978-1734314509 978-1788399081 978-1788399083 }
qw{ 978-0596528126 978-0596528120 978-1788399081 978-1788399083 }
[ dup isbn13? "good" "bad" ? "%s: %s\n" printf ] each</syntaxhighlight>
[ dup isbn13? "good" "bad" ? "%s: %s\n" printf ] each</syntaxhighlight>
{{out}}
{{out}}
<pre>
<pre>
978-1734314502: good
978-0596528126: good
978-1734314509: bad
978-0596528120: bad
978-1788399081: good
978-1788399081: good
978-1788399083: bad
978-1788399083: bad
Line 1,442: Line 1,442:
In Forth, a "true" value is indicated by "-1".
In Forth, a "true" value is indicated by "-1".
<pre>
<pre>
s" 978-1734314502" isbn? . -1 ok
s" 978-0596528126" isbn? . -1 ok
s" 978-1734314509" isbn? . 0 ok
s" 978-0596528120" isbn? . 0 ok
s" 978-1788399081" isbn? . -1 ok
s" 978-1788399081" isbn? . -1 ok
s" 978-1788399083" isbn? . 0 ok
s" 978-1788399083" isbn? . 0 ok
Line 1,453: Line 1,453:
implicit none
implicit none


character(len=14), dimension(4), parameter :: isbns=["978-1734314502", "978-1734314509", "978-1788399081", "978-1788399083"]
character(len=14), dimension(4), parameter :: isbns=["978-0596528126", "978-0596528120", "978-1788399081", "978-1788399083"]
integer :: i
integer :: i


Line 1,490: Line 1,490:
{{out}}
{{out}}
<pre>
<pre>
978-1734314502 : good
978-0596528126 : good
978-1734314509 : bad
978-0596528120 : bad
978-1788399081 : good
978-1788399081 : good
978-1788399083 : bad
978-1788399083 : bad
Line 1,525: Line 1,525:
end function
end function


dim as string isbns(0 to 3) = { "978-1734314502", "978-1734314509", "978-1788399081", "978-1788399083" }
dim as string isbns(0 to 3) = { "978-0596528126", "978-0596528120", "978-1788399081", "978-1788399083" }
dim as uinteger i
dim as uinteger i
for i = 0 to 3
for i = 0 to 3
Line 1,537: Line 1,537:
{{out}}
{{out}}
<pre>
<pre>
978-1734314502: good
978-0596528126: good
978-1734314509: bad
978-0596528120: bad
978-1788399081: good
978-1788399081: good
978-1788399083: bad
978-1788399083: bad
Line 1,565: Line 1,565:


{{out}}
{{out}}
<pre>978-1734314502 Valid ISBN13
<pre>978-0596528126 Valid ISBN13
978-1734314509 Inalid ISBN13
978-0596528120 Inalid ISBN13
978-1788399081 Valid ISBN13
978-1788399081 Valid ISBN13
978-1788399083 Inalid ISBN13</pre>
978-1788399083 Inalid ISBN13</pre>
Line 1,588: Line 1,588:
<syntaxhighlight lang="vbnet">Public Sub Main()
<syntaxhighlight lang="vbnet">Public Sub Main()
Dim isbn As String[] = ["978-1734314502", "978-1734314509", "978-1788399081", "978-1788399083", "978-2-74839-908-0", "978-2-74839-908-5", "978 1 86197 876 9"]
Dim isbn As String[] = ["978-0596528126", "978-0596528120", "978-1788399081", "978-1788399083", "978-2-74839-908-0", "978-2-74839-908-5", "978 1 86197 876 9"]
For n As Integer = 1 To isbn.Count
For n As Integer = 1 To isbn.Count
Line 1,645: Line 1,645:


func main() {
func main() {
isbns := []string{"978-1734314502", "978-1734314509", "978-1788399081", "978-1788399083"}
isbns := []string{"978-0596528126", "978-0596528120", "978-1788399081", "978-1788399083"}
for _, isbn := range isbns {
for _, isbn := range isbns {
res := "bad"
res := "bad"
Line 1,657: Line 1,657:
{{out}}
{{out}}
<pre>
<pre>
978-1734314502: good
978-0596528126: good
978-1734314509: bad
978-0596528120: bad
978-1788399081: good
978-1788399081: good
978-1788399083: bad
978-1788399083: bad
Line 1,687: Line 1,687:
mapM_
mapM_
(printf "%s: Valid: %s\n" <*> (show . validIsbn13))
(printf "%s: Valid: %s\n" <*> (show . validIsbn13))
[ "978-1734314502",
[ "978-0596528126",
"978-1734314509",
"978-0596528120",
"978-1788399081",
"978-1788399081",
"978-1788399083"
"978-1788399083"
]</syntaxhighlight>
]</syntaxhighlight>
{{out}}
{{out}}
<pre>978-1734314502: Valid: True
<pre>978-0596528126: Valid: True
978-1734314509: Valid: False
978-0596528120: Valid: False
978-1788399081: Valid: True
978-1788399081: Valid: True
978-1788399083: Valid: False</pre>
978-1788399083: Valid: False</pre>
Line 1,715: Line 1,715:
mapM_
mapM_
(print . ((,) <*> isISBN13))
(print . ((,) <*> isISBN13))
[ "978-1734314502",
[ "978-0596528126",
"978-1734314509",
"978-0596528120",
"978-1788399081",
"978-1788399081",
"978-1788399083"
"978-1788399083"
]</syntaxhighlight>
]</syntaxhighlight>
{{Out}}
{{Out}}
<pre>("978-1734314502",True)
<pre>("978-0596528126",True)
("978-1734314509",False)
("978-0596528120",False)
("978-1788399081",True)
("978-1788399081",True)
("978-1788399083",False)</pre>
("978-1788399083",False)</pre>
Line 1,764: Line 1,764:
{{out}}
{{out}}


<syntaxhighlight lang="j"> isbn13c;._1 ' 978-1734314502 978-1734314509 978-1788399081 978-1788399083'
<syntaxhighlight lang="j"> isbn13c;._1 ' 978-0596528126 978-0596528120 978-1788399081 978-1788399083'
1 0 1 0</syntaxhighlight>
1 0 1 0</syntaxhighlight>


Line 1,817: Line 1,817:
An alternate demonstration
An alternate demonstration
<syntaxhighlight lang="java">public static void main(){
<syntaxhighlight lang="java">public static void main(){
System.out.println(isISBN13("978-1734314502"));
System.out.println(isISBN13("978-0596528126"));
System.out.println(isISBN13("978-1734314509"));
System.out.println(isISBN13("978-0596528120"));
System.out.println(isISBN13("978-1788399081"));
System.out.println(isISBN13("978-1788399081"));
System.out.println(isISBN13("978-1788399083"));
System.out.println(isISBN13("978-1788399083"));
Line 1,856: Line 1,856:


def testingcodes:
def testingcodes:
["978-1734314502", "978-1734314509",
["978-0596528126", "978-0596528120",
"978-1788399081", "978-1788399083"];
"978-1788399081", "978-1788399083"];
Line 1,864: Line 1,864:
{{out}}
{{out}}
<pre>
<pre>
978-1734314502: good
978-0596528126: good
978-1734314509: bad
978-0596528120: bad
978-1788399081: good
978-1788399081: good
978-1788399083: bad
978-1788399083: bad
Line 1,876: Line 1,876:
end
end


const testingcodes = ["978-1734314502", "978-1734314509",
const testingcodes = ["978-0596528126", "978-0596528120",
"978-1788399081", "978-1788399083"]
"978-1788399081", "978-1788399083"]


Line 1,884: Line 1,884:
</syntaxhighlight>{{out}}
</syntaxhighlight>{{out}}
<pre>
<pre>
978-1734314502: good
978-0596528126: good
978-1734314509: bad
978-0596528120: bad
978-1788399081: good
978-1788399081: good
978-1788399083: bad
978-1788399083: bad
Line 1,918: Line 1,918:
describe("ISBN Utilities") {
describe("ISBN Utilities") {
mapOf(
mapOf(
"978-1734314502" to true,
"978-0596528126" to true,
"978-1734314509" to false,
"978-0596528120" to false,
"978-1788399081" to true,
"978-1788399081" to true,
"978-1788399083" to false
"978-1788399083" to false
Line 1,935: Line 1,935:
{{out}}
{{out}}
<pre>
<pre>
978-1734314502: good
978-0596528126: good
978-1734314509: bad
978-0596528120: bad
978-1788399081: good
978-1788399081: good
978-1788399083: bad
978-1788399083: bad
Line 2,025: Line 2,025:


function main()
function main()
test("978-1734314502")
test("978-0596528126")
test("978-1734314509")
test("978-0596528120")
test("978-1788399081")
test("978-1788399081")
test("978-1788399083")
test("978-1788399083")
Line 2,033: Line 2,033:
main()</syntaxhighlight>
main()</syntaxhighlight>
{{out}}
{{out}}
<pre>978-1734314502: good
<pre>978-0596528126: good
978-1734314509: bad
978-0596528120: bad
978-1788399081: good
978-1788399081: good
978-1788399083: bad</pre>
978-1788399083: bad</pre>
Line 2,051: Line 2,051:
]
]
]
]
ValidISBNQ["978-1734314502"]
ValidISBNQ["978-0596528126"]
ValidISBNQ["978-1734314509"]
ValidISBNQ["978-0596528120"]
ValidISBNQ["978-1788399081"]
ValidISBNQ["978-1788399081"]
ValidISBNQ["978-1788399083"]</syntaxhighlight>
ValidISBNQ["978-1788399083"]</syntaxhighlight>
Line 2,128: Line 2,128:


BEGIN
BEGIN
check('978-1734314502');
check('978-0596528126');
check('978-1734314509');
check('978-0596528120');
check('978-1788399081');
check('978-1788399081');
check('978-1788399083');
check('978-1788399083');
END ISBN.</syntaxhighlight>
END ISBN.</syntaxhighlight>
{{out}}
{{out}}
<pre>978-1734314502: good
<pre>978-0596528126: good
978-1734314509: bad
978-0596528120: bad
978-1788399081: good
978-1788399081: good
978-1788399083: bad</pre>
978-1788399083: bad</pre>
Line 2,168: Line 2,168:
end
end


isbns = {"978-1734314502", "978-1734314509", "978-1788399081", "978-1788399083"}
isbns = {"978-0596528126", "978-0596528120", "978-1788399081", "978-1788399083"}
for isbn in isbns
for isbn in isbns
res = "bad"
res = "bad"
Line 2,178: Line 2,178:
end</syntaxhighlight>
end</syntaxhighlight>
{{out}}
{{out}}
<pre>978-1734314502: good
<pre>978-0596528126: good
978-1734314509: bad
978-0596528120: bad
978-1788399081: good
978-1788399081: good
978-1788399083: bad</pre>
978-1788399083: bad</pre>
Line 2,197: Line 2,197:


when is_main_module:
when is_main_module:
let isbns = [ "978-1734314502", "978-1734314509",
let isbns = [ "978-0596528126", "978-0596528120",
"978-1788399081", "978-1788399083" ]
"978-1788399081", "978-1788399083" ]
for isbn in isbns:
for isbn in isbns:
Line 2,204: Line 2,204:
{{out}}
{{out}}
<pre>
<pre>
978-1734314502: good
978-0596528126: good
978-1734314509: bad
978-0596528120: bad
978-1788399081: good
978-1788399081: good
978-1788399083: bad
978-1788399083: bad
Line 2,292: Line 2,292:
{ === MAIN ============================================================= }
{ === MAIN ============================================================= }
begin
begin
writeLn(isValidISBNString('978-1734314502'));
writeLn(isValidISBNString('978-0596528126'));
writeLn(isValidISBNString('978-1734314509'));
writeLn(isValidISBNString('978-0596528120'));
writeLn(isValidISBNString('978-1788399081'));
writeLn(isValidISBNString('978-1788399081'));
writeLn(isValidISBNString('978-1788399083'))
writeLn(isValidISBNString('978-1788399083'))
Line 2,314: Line 2,314:
}
}


for (<978-1734314502 978-1734314509 978-1788399081 978-1788399083 978-2-74839-908-0 978-2-74839-908-5>) {
for (<978-0596528126 978-0596528120 978-1788399081 978-1788399083 978-2-74839-908-0 978-2-74839-908-5>) {
my($isbn,$check) = /(.*)(.)/;
my($isbn,$check) = /(.*)(.)/;
my $check_d = check_digit($isbn);
my $check_d = check_digit($isbn);
Line 2,320: Line 2,320:
}</syntaxhighlight>
}</syntaxhighlight>
{{out}}
{{out}}
<pre>978-1734314502 : Good
<pre>978-0596528126 : Good
978-1734314509 : Bad check-digit 9; should be 2
978-0596528120 : Bad check-digit 9; should be 2
978-1788399081 : Good
978-1788399081 : Good
978-1788399083 : Bad check-digit 3; should be 1
978-1788399083 : Bad check-digit 3; should be 1
Line 2,347: Line 2,347:
<span style="color: #008080;">end</span> <span style="color: #008080;">procedure</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">procedure</span>
<span style="color: #008080;">constant</span> <span style="color: #000000;">isbns</span> <span style="color: #0000FF;">=</span> <span style="color: #0000FF;">{</span><span style="color: #008000;">"978-1734314502"</span><span style="color: #0000FF;">,</span> <span style="color: #008000;">"978-1734314509"</span><span style="color: #0000FF;">,</span> <span style="color: #008000;">"978-1788399081"</span><span style="color: #0000FF;">,</span> <span style="color: #008000;">"978-1788399083"</span><span style="color: #0000FF;">,</span>
<span style="color: #008080;">constant</span> <span style="color: #000000;">isbns</span> <span style="color: #0000FF;">=</span> <span style="color: #0000FF;">{</span><span style="color: #008000;">"978-0596528126"</span><span style="color: #0000FF;">,</span> <span style="color: #008000;">"978-0596528120"</span><span style="color: #0000FF;">,</span> <span style="color: #008000;">"978-1788399081"</span><span style="color: #0000FF;">,</span> <span style="color: #008000;">"978-1788399083"</span><span style="color: #0000FF;">,</span>
<span style="color: #008000;">"978-2-74839-908-0"</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"978-2-74839-908-5"</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"978 1 86197 876 9"</span><span style="color: #0000FF;">}</span>
<span style="color: #008000;">"978-2-74839-908-0"</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"978-2-74839-908-5"</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"978 1 86197 876 9"</span><span style="color: #0000FF;">}</span>
<span style="color: #008080;">for</span> <span style="color: #000000;">i</span><span style="color: #0000FF;">=</span><span style="color: #000000;">1</span> <span style="color: #008080;">to</span> <span style="color: #7060A8;">length</span><span style="color: #0000FF;">(</span><span style="color: #000000;">isbns</span><span style="color: #0000FF;">)</span> <span style="color: #008080;">do</span> <span style="color: #000000;">check_isbn13</span><span style="color: #0000FF;">(</span><span style="color: #000000;">isbns</span><span style="color: #0000FF;">[</span><span style="color: #000000;">i</span><span style="color: #0000FF;">])</span> <span style="color: #008080;">end</span> <span style="color: #008080;">for</span>
<span style="color: #008080;">for</span> <span style="color: #000000;">i</span><span style="color: #0000FF;">=</span><span style="color: #000000;">1</span> <span style="color: #008080;">to</span> <span style="color: #7060A8;">length</span><span style="color: #0000FF;">(</span><span style="color: #000000;">isbns</span><span style="color: #0000FF;">)</span> <span style="color: #008080;">do</span> <span style="color: #000000;">check_isbn13</span><span style="color: #0000FF;">(</span><span style="color: #000000;">isbns</span><span style="color: #0000FF;">[</span><span style="color: #000000;">i</span><span style="color: #0000FF;">])</span> <span style="color: #008080;">end</span> <span style="color: #008080;">for</span>
Line 2,353: Line 2,353:
{{out}}
{{out}}
<pre>
<pre>
978-1734314502: good
978-0596528126: good
978-1734314509: bad
978-0596528120: bad
978-1788399081: good
978-1788399081: good
978-1788399083: bad
978-1788399083: bad
Line 2,378: Line 2,378:
(if (isbn13? A) 'ok 'fail) ) )
(if (isbn13? A) 'ok 'fail) ) )
(quote
(quote
"978-1734314502"
"978-0596528126"
"978-1734314509"
"978-0596528120"
"978-1-86197-876-9"
"978-1-86197-876-9"
"978-2-74839-908-5"
"978-2-74839-908-5"
Line 2,385: Line 2,385:
{{out}}
{{out}}
<pre>
<pre>
978-1734314502 ok
978-0596528126 ok
978-1734314509 fail
978-0596528120 fail
978-1-86197-876-9 ok
978-1-86197-876-9 ok
978-2-74839-908-5 fail
978-2-74839-908-5 fail
Line 2,428: Line 2,428:
/* TESTS */
/* TESTS */
DECLARE TEST (4) ADDRESS;
DECLARE TEST (4) ADDRESS;
TEST(0) = .'978-1734314502$';
TEST(0) = .'978-0596528126$';
TEST(1) = .'978-1734314509$';
TEST(1) = .'978-0596528120$';
TEST(2) = .'978-1788399081$';
TEST(2) = .'978-1788399081$';
TEST(3) = .'978-1788399083$';
TEST(3) = .'978-1788399083$';
Line 2,447: Line 2,447:
EOF</syntaxhighlight>
EOF</syntaxhighlight>
{{out}}
{{out}}
<pre>978-1734314502: GOOD
<pre>978-0596528126: GOOD
978-1734314509: BAD
978-0596528120: BAD
978-1788399081: GOOD
978-1788399081: GOOD
978-1788399083: BAD</pre>
978-1788399083: BAD</pre>
Line 2,456: Line 2,456:
function Get-ISBN13 {
function Get-ISBN13 {
$codes = (
$codes = (
"978-1734314502",
"978-0596528126",
"978-1734314509",
"978-0596528120",
"978-1788399081",
"978-1788399081",
"978-1788399083"
"978-1788399083"
Line 2,496: Line 2,496:
{{out}}
{{out}}
<pre>
<pre>
978-1734314502 Good
978-0596528126 Good
978-1734314509 Bad
978-0596528120 Bad
978-1788399081 Good
978-1788399081 Good
978-1788399083 Bad
978-1788399083 Bad
Line 2,518: Line 2,518:


If OpenConsole()
If OpenConsole()
TestISBN13("978-1734314502")
TestISBN13("978-0596528126")
TestISBN13("978-1734314509")
TestISBN13("978-0596528120")
TestISBN13("978-1788399081")
TestISBN13("978-1788399081")
TestISBN13("978-1788399083")
TestISBN13("978-1788399083")
Line 2,525: Line 2,525:
EndIf</syntaxhighlight>
EndIf</syntaxhighlight>
{{out}}
{{out}}
<pre>978-1734314502 good
<pre>978-0596528126 good
978-1734314509 bad
978-0596528120 bad
978-1788399081 good
978-1788399081 good
978-1788399083 bad
978-1788399083 bad
Line 2,542: Line 2,542:
if __name__ == '__main__':
if __name__ == '__main__':
tests = '''
tests = '''
978-1734314502
978-0596528126
978-1734314509
978-0596528120
978-1788399081
978-1788399081
978-1788399083'''.strip().split()
978-1788399083'''.strip().split()
Line 2,550: Line 2,550:


{{out}}
{{out}}
<pre>ISBN13 978-1734314502 validates True
<pre>ISBN13 978-0596528126 validates True
ISBN13 978-1734314509 validates False
ISBN13 978-0596528120 validates False
ISBN13 978-1788399081 validates True
ISBN13 978-1788399081 validates True
ISBN13 978-1788399083 validates False</pre>
ISBN13 978-1788399083 validates False</pre>
Line 2,587: Line 2,587:
print('\n'.join(
print('\n'.join(
repr((s, isISBN13(s))) for s
repr((s, isISBN13(s))) for s
in ["978-1734314502",
in ["978-0596528126",
"978-1734314509",
"978-0596528120",
"978-1788399081",
"978-1788399081",
"978-1788399083"
"978-1788399083"
Line 2,600: Line 2,600:
</syntaxhighlight>
</syntaxhighlight>
{{Out}}
{{Out}}
<pre>('978-1734314502', True)
<pre>('978-0596528126', True)
('978-1734314509', False)
('978-0596528120', False)
('978-1788399081', True)
('978-1788399081', True)
('978-1788399083', False)</pre>
('978-1788399083', False)</pre>
Line 2,634: Line 2,634:
else [ say "Bad" ] cr ] is isbn-test ( $ --> )
else [ say "Bad" ] cr ] is isbn-test ( $ --> )


$ '978-1734314502' isbn-test
$ '978-0596528126' isbn-test
$ '978-1734314509' isbn-test
$ '978-0596528120' isbn-test
$ '978-1788399081' isbn-test
$ '978-1788399081' isbn-test
$ '978-1788399083' isbn-test</syntaxhighlight>
$ '978-1788399083' isbn-test</syntaxhighlight>
{{out}}
{{out}}
<pre>
<pre>
978-1734314502: Good
978-0596528126: Good
978-1734314509: Bad
978-0596528120: Bad
978-1788399081: Good
978-1788399081: Good
978-1788399083: Bad
978-1788399083: Bad
Line 2,659: Line 2,659:
(module+ test
(module+ test
(require rackunit)
(require rackunit)
(check-true (isbn13-check-digit-valid? "978-1734314502"))
(check-true (isbn13-check-digit-valid? "978-0596528126"))
(check-false (isbn13-check-digit-valid? "978-1734314509"))
(check-false (isbn13-check-digit-valid? "978-0596528120"))
(check-true (isbn13-check-digit-valid? "978-1788399081"))
(check-true (isbn13-check-digit-valid? "978-1788399081"))
(check-false (isbn13-check-digit-valid? "978-1788399083")))</syntaxhighlight>
(check-false (isbn13-check-digit-valid? "978-1788399083")))</syntaxhighlight>
Line 2,683: Line 2,683:
"Bad check-digit $check; should be $check-digit"
"Bad check-digit $check; should be $check-digit"
} for words <
} for words <
978-1734314502
978-0596528126
978-1734314509
978-0596528120
978-1788399081
978-1788399081
978-1788399083
978-1788399083
Line 2,691: Line 2,691:
>;</syntaxhighlight>
>;</syntaxhighlight>
{{out}}
{{out}}
<pre>978-1734314502 : Good
<pre>978-0596528126 : Good
978-1734314509 : Bad check-digit 9; should be 2
978-0596528120 : Bad check-digit 9; should be 2
978-1788399081 : Good
978-1788399081 : Good
978-1788399083 : Bad check-digit 3; should be 1
978-1788399083 : Bad check-digit 3; should be 1
Line 2,719: Line 2,719:


; check given examples
; check given examples
foreach [str] ["978-1734314502" "978-1734314509" "978-1788399081" "978-1788399083"] [
foreach [str] ["978-0596528126" "978-0596528120" "978-1788399081" "978-1788399083"] [
prin str
prin str
prin " - "
prin " - "
Line 2,728: Line 2,728:
{{out}}
{{out}}
<pre>
<pre>
978-1734314502 - true
978-0596528126 - true
978-1734314509 - false
978-0596528120 - false
978-1788399081 - true
978-1788399081 - true
978-1788399083 - false
978-1788399083 - false
Line 2,738: Line 2,738:
<syntaxhighlight lang="rexx">/*REXX pgm validates the check digit of an ISBN─13 code (it may have embedded minuses).*/
<syntaxhighlight lang="rexx">/*REXX pgm validates the check digit of an ISBN─13 code (it may have embedded minuses).*/
parse arg $ /*obtain optional arguments from the CL*/
parse arg $ /*obtain optional arguments from the CL*/
if $='' | if $="," then $= '978-1734314502 978-1734314509 978-1788399081 978-1788399083'
if $='' | if $="," then $= '978-0596528126 978-0596528120 978-1788399081 978-1788399083'
@ISBN= "ISBN─13 code isn't" /*a literal used when displaying msgs. */
@ISBN= "ISBN─13 code isn't" /*a literal used when displaying msgs. */
/* [↓] remove all minuses from X code.*/
/* [↓] remove all minuses from X code.*/
Line 2,767: Line 2,767:
load "stdlib.ring"
load "stdlib.ring"


isbn = ["978-1734314502","978-1734314509", "978-1788399081", "978-1788399083","978-2-74839-908-0","978-2-74839-908-5","978 1 86197 876 9"]
isbn = ["978-0596528126","978-0596528120", "978-1788399081", "978-1788399083","978-2-74839-908-0","978-2-74839-908-5","978 1 86197 876 9"]


for n = 1 to len(isbn)
for n = 1 to len(isbn)
Line 2,792: Line 2,792:
Output:
Output:
<pre>
<pre>
978-1734314502: true
978-0596528126: true
978-1734314509: bad
978-0596528120: bad
978-1788399081: true
978-1788399081: true
978-1788399083: bad
978-1788399083: bad
Line 2,834: Line 2,834:
end
end


isbns = ["978-1734314502", "978-1734314509", "978-1788399081", "978-1788399083"]
isbns = ["978-0596528126", "978-0596528120", "978-1788399081", "978-1788399083"]
isbns.each{|isbn| puts "#{isbn}: #{validISBN13?(isbn)}" }
isbns.each{|isbn| puts "#{isbn}: #{validISBN13?(isbn)}" }
</syntaxhighlight>{{out}}
</syntaxhighlight>{{out}}
<pre>978-1734314502: true
<pre>978-0596528126: true
978-1734314509: false
978-0596528120: false
978-1788399081: true
978-1788399081: true
978-1788399083: false
978-1788399083: false
Line 2,845: Line 2,845:
=={{header|Rust}}==
=={{header|Rust}}==
<syntaxhighlight lang="rust">fn main() {
<syntaxhighlight lang="rust">fn main() {
let isbns = ["978-1734314502", "978-1734314509", "978-1788399081", "978-1788399083"];
let isbns = ["978-0596528126", "978-0596528120", "978-1788399081", "978-1788399083"];
isbns.iter().for_each(|isbn| println!("{}: {}", isbn, check_isbn(isbn)));
isbns.iter().for_each(|isbn| println!("{}: {}", isbn, check_isbn(isbn)));
}
}
Line 2,861: Line 2,861:
{{out}}
{{out}}
<pre>
<pre>
978-1734314502: true
978-0596528126: true
978-1734314509: false
978-0596528120: false
978-1788399081: true
978-1788399081: true
978-1788399083: false
978-1788399083: false
Line 2,898: Line 2,898:
var string: str is "";
var string: str is "";
begin
begin
for str range [] ("978-1734314502", "978-1734314509", "978-1788399081", "978-1788399083") do
for str range [] ("978-0596528126", "978-0596528120", "978-1788399081", "978-1788399083") do
writeln(str <& ": " <& isISBN13(str));
writeln(str <& ": " <& isISBN13(str));
end for;
end for;
Line 2,904: Line 2,904:
{{out}}
{{out}}
<pre>
<pre>
978-1734314502: TRUE
978-0596528126: TRUE
978-1734314509: FALSE
978-0596528120: FALSE
978-1788399081: TRUE
978-1788399081: TRUE
978-1788399083: FALSE
978-1788399083: FALSE
Line 2,922: Line 2,922:
end
end


val test = ["978-1734314502", "978-1734314509", "978-1788399081", "978-1788399083"]
val test = ["978-0596528126", "978-0596528120", "978-1788399081", "978-1788399083"]
val () = (print
val () = (print
o concat
o concat
o map (fn s => s ^ (if checkISBN s then ": good\n" else ": bad\n"))) test</syntaxhighlight>
o map (fn s => s ^ (if checkISBN s then ": good\n" else ": bad\n"))) test</syntaxhighlight>
{{out}}
{{out}}
<pre>978-1734314502: good
<pre>978-0596528126: good
978-1734314509: bad
978-0596528120: bad
978-1788399081: good
978-1788399081: good
978-1788399083: bad</pre>
978-1788399083: bad</pre>
Line 2,949: Line 2,949:


let cases = [
let cases = [
"978-1734314502",
"978-0596528126",
"978-1734314509",
"978-0596528120",
"978-1788399081",
"978-1788399081",
"978-1788399083"
"978-1788399083"
Line 2,962: Line 2,962:
{{out}}
{{out}}


<pre>978-1734314502 => good
<pre>978-0596528126 => good
978-1734314509 => bad
978-0596528120 => bad
978-1788399081 => good
978-1788399081 => good
978-1788399083 => bad</pre>
978-1788399083 => bad</pre>
Line 2,984: Line 2,984:
}
}
foreach test {
foreach test {
978-1734314502
978-0596528126
978-1734314509
978-0596528120
978-1788399081
978-1788399081
978-1788399083
978-1788399083
Line 2,991: Line 2,991:
</syntaxhighlight>
</syntaxhighlight>
{{out}}
{{out}}
<pre>978-1734314502:true
<pre>978-0596528126:true
978-1734314509:false
978-0596528120:false
978-1788399081:true
978-1788399081:true
978-1788399083:false</pre>
978-1788399083:false</pre>
Line 3,013: Line 3,013:
=={{header|uBasic/4tH}}==
=={{header|uBasic/4tH}}==
{{works with|version 3.64.0}}
{{works with|version 3.64.0}}
<syntaxhighlight lang="text">a := "978-1734314502"
<syntaxhighlight lang="text">a := "978-0596528126"
Print Show(a), Show (Iif (Func(_IsISBN (a)), "good", "bad"))
Print Show(a), Show (Iif (Func(_IsISBN (a)), "good", "bad"))


a := "978-1734314509"
a := "978-0596528120"
Print Show(a), Show (Iif (Func(_IsISBN (a)), "good", "bad"))
Print Show(a), Show (Iif (Func(_IsISBN (a)), "good", "bad"))


Line 3,041: Line 3,041:
Return ((c@ % 10) = 0) ' modulus 10 must be zero</syntaxhighlight>
Return ((c@ % 10) = 0) ' modulus 10 must be zero</syntaxhighlight>
{{out}}
{{out}}
<pre>978-1734314502 good
<pre>978-0596528126 good
978-1734314509 bad
978-0596528120 bad
978-1788399081 good
978-1788399081 good
978-1788399083 bad
978-1788399083 bad
Line 3,060: Line 3,060:
}
}


for isbn in 978-1734314502 978-1734314509 978-1788399081 978-1788399083; do
for isbn in 978-0596528126 978-0596528120 978-1788399081 978-1788399083; do
printf '%s: ' "$isbn"
printf '%s: ' "$isbn"
if check_isbn13 "$isbn"; then
if check_isbn13 "$isbn"; then
Line 3,069: Line 3,069:
done</syntaxhighlight>
done</syntaxhighlight>
{{Out}}
{{Out}}
<pre>978-1734314502: OK
<pre>978-0596528126: OK
978-1734314509: NOT OK
978-0596528120: NOT OK
978-1788399081: OK
978-1788399081: OK
978-1788399083: NOT OK</pre>
978-1788399083: NOT OK</pre>
Line 3,097: Line 3,097:


Sub Main()
Sub Main()
Console.WriteLine(CheckISBN13("978-1734314502"))
Console.WriteLine(CheckISBN13("978-0596528126"))
Console.WriteLine(CheckISBN13("978-1734314509"))
Console.WriteLine(CheckISBN13("978-0596528120"))
Console.WriteLine(CheckISBN13("978-1788399081"))
Console.WriteLine(CheckISBN13("978-1788399081"))
Console.WriteLine(CheckISBN13("978-1788399083"))
Console.WriteLine(CheckISBN13("978-1788399083"))
Line 3,137: Line 3,137:
fn main() {
fn main() {
isbns := ["978-1734314502", "978-1734314509", "978-1788399081", "978-1788399083"]
isbns := ["978-0596528126", "978-0596528120", "978-1788399081", "978-1788399083"]
for isbn in isbns {
for isbn in isbns {
mut res := "bad"
mut res := "bad"
Line 3,149: Line 3,149:
{{out}}
{{out}}
<pre>
<pre>
978-1734314502: good
978-0596528126: good
978-1734314509: bad
978-0596528120: bad
978-1788399081: good
978-1788399081: good
978-1788399083: bad
978-1788399083: bad
Line 3,173: Line 3,173:
}
}


var tests = ["978-1734314502", "978-1734314509", "978-1788399081", "978-1788399083"]
var tests = ["978-0596528126", "978-0596528120", "978-1788399081", "978-1788399083"]
for (test in tests) {
for (test in tests) {
System.print("%(test) -> %(isbn13.call(test) ? "good" : "bad")")
System.print("%(test) -> %(isbn13.call(test) ? "good" : "bad")")
Line 3,180: Line 3,180:
{{out}}
{{out}}
<pre>
<pre>
978-1734314502 -> good
978-0596528126 -> good
978-1734314509 -> bad
978-0596528120 -> bad
978-1788399081 -> good
978-1788399081 -> good
978-1788399083 -> bad
978-1788399083 -> bad
Line 3,207: Line 3,207:
];
];


[ISBN13("978-1734314502");
[ISBN13("978-0596528126");
ISBN13("978-1734314509");
ISBN13("978-0596528120");
ISBN13("978-1788399081");
ISBN13("978-1788399081");
ISBN13("978-1788399083");
ISBN13("978-1788399083");
Line 3,217: Line 3,217:
{{out}}
{{out}}
<pre>
<pre>
978-1734314502: good
978-0596528126: good
978-1734314509: bad
978-0596528120: bad
978-1788399081: good
978-1788399081: good
978-1788399083: bad
978-1788399083: bad
Line 3,226: Line 3,226:


=={{header|zkl}}==
=={{header|zkl}}==
<syntaxhighlight lang="zkl">fcn ISBN13_check(isbn){ // "978-1734314502", throws on invalid digits
<syntaxhighlight lang="zkl">fcn ISBN13_check(isbn){ // "978-0596528126", throws on invalid digits
var [const] one3=("13"*6 + 1).split("").apply("toInt"); // examine 13 digits
var [const] one3=("13"*6 + 1).split("").apply("toInt"); // examine 13 digits
// one3=("13"*6) if you want to calculate what the check digit should be
// one3=("13"*6) if you want to calculate what the check digit should be
Line 3,233: Line 3,233:
<syntaxhighlight lang="zkl">isbns:=
<syntaxhighlight lang="zkl">isbns:=
#<<<"
#<<<"
978-1734314502
978-0596528126
978-1734314509
978-0596528120
978-1788399081
978-1788399081
978-1788399083
978-1788399083
Line 3,244: Line 3,244:
{{out}}
{{out}}
<pre>
<pre>
978-1734314502 Good
978-0596528126 Good
978-1734314509 Bad
978-0596528120 Bad
978-1788399081 Good
978-1788399081 Good
978-1788399083 Bad
978-1788399083 Bad