ISBN13 check digit: Difference between revisions

for clarity, replaced ISBN for opCode with ISBN for Python Interviews (which I have no vested interest in)
(for clarity, replaced ISBN for opCode with ISBN for Python Interviews (which I have no vested interest in))
Line 34:
R product % 10 == 0
 
V tests = |‘978-17343145020596528126
978-17343145090596528120
978-1788399081
978-1788399083’.split("\n")
Line 44:
{{out}}
<pre>
ISBN13 978-17343145020596528126 validates 1B
ISBN13 978-17343145090596528120 validates 0B
ISBN13 978-1788399081 validates 1B
ISBN13 978-1788399083 validates 0B
Line 122:
{{out}}
 
<pre>A>isbn13 978-17343145020596528126
good
A>isbn13 978-17343145090596528120
bad
A>isbn13 978-1788399081
Line 190:
{{out}}
 
<pre>C:\>isbn13 978-17343145020596528126
good
C:\>isbn13 978-17343145090596528120
bad
C:\>isbn13 978-1788399081
Line 241:
Put(125) PutE() ;clear screen
 
Test("978-17343145020596528126")
Test("978-17343145090596528120")
Test("978-1788399081")
Test("978-1788399083")
Line 249:
[https://gitlab.com/amarok8bit/action-rosetta-code/-/raw/master/images/ISBN13_check_digit.png Screenshot from Atari 8-bit computer]
<pre>
978-17343145020596528126 is correct
978-17343145090596528120 is incorrect
978-1788399081 is correct
978-1788399083 is incorrect
Line 288:
end Show;
begin
Show ("978-17343145020596528126");
Show ("978-17343145090596528120");
Show ("978-1788399081");
Show ("978-1788399083");
end ISBN_Check;</syntaxhighlight>
{{out}}
<pre>978-17343145020596528126 Good
978-17343145090596528120 Bad
978-1788399081 Good
978-1788399083 Bad</pre>
Line 323:
END; # check isbn13 #
# task test cases #
[]STRING tests = ( "978-17343145020596528126", "978-17343145090596528120", "978-1788399081", "978-1788399083" );
[]BOOL expected = ( TRUE, FALSE, TRUE, FALSE );
FOR pos FROM LWB tests TO UPB tests DO
Line 338:
{{out}}
<pre>
978-17343145020596528126: good
978-17343145090596528120: bad
978-1788399081: good
978-1788399083: bad
Line 353:
{{out}}
 
<pre> check_isbn13¨ '978-17343145020596528126' '978-17343145090596528120' '978-1788399081' '978-1788399083'
1 0 1 0</pre>
 
Line 388:
end script
map(test, {"978-17343145020596528126", "978-17343145090596528120", ¬
"978-1788399081", "978-1788399083"})
end run
Line 565:
end zipWith</syntaxhighlight>
{{Out}}
<pre>{{"978-17343145020596528126", true}, {"978-17343145090596528120", false}, {"978-1788399081", true}, {"978-1788399083", false}}</pre>
 
===Straightforward===
Line 599:
set output to {}
set verdicts to {"bad", "good"}
repeat with thisISBN13 in {"978-17343145020596528126", "978-17343145090596528120", "978-1788399081", "978-1788399083"}
set isValid to validateISBN13(thisISBN13)
set end of output to thisISBN13 & ": " & item ((isValid as integer) + 1) of verdicts
Line 611:
 
{{output}}
<pre>"978-17343145020596528126: good
978-17343145090596528120: bad
978-1788399081: good
978-1788399083: bad"</pre>
Line 660:
 
tests: [
"978-17343145020596528126" "978-17343145090596528120"
"978-1788399081" "978-1788399083"
]
Line 670:
{{out}}
 
<pre>978-17343145020596528126 => true
978-17343145090596528120 => false
978-1788399081 => true
978-1788399083 => false</pre>
Line 682:
}</syntaxhighlight>
Examples:<syntaxhighlight lang="autohotkey">output := ""
nums := ["978-17343145020596528126","978-17343145090596528120","978-1788399081","978-1788399083"]
for i, n in nums
output .= ISBN13_check_digit(n) "`n"
Line 688:
return</syntaxhighlight>
{{out}}
<pre>978-17343145020596528126 (good)
978-17343145090596528120 (bad)
978-1788399081 (good)
978-1788399083 (bad)</pre>
Line 697:
# syntax: GAWK -f ISBN13_CHECK_DIGIT.AWK
BEGIN {
arr[++n] = "978-17343145020596528126"
arr[++n] = "978-17343145090596528120"
arr[++n] = "978-1788399081"
arr[++n] = "978-1788399083"
Line 720:
{{out}}
<pre>
978-17343145020596528126 OK
978-17343145090596528120 NG check digit S/B 2
978-1788399081 OK
978-1788399083 NG check digit S/B 1
Line 731:
{{trans|Ring}}
<syntaxhighlight lang="vb">arraybase 1
dim isbn = {"978-17343145020596528126", "978-17343145090596528120", "978-1788399081", "978-1788399083", "978-2-74839-908-0", "978-2-74839-908-5", "978 1 86197 876 9"}
 
for n = 1 to isbn[?]
Line 782:
 
let start() be
$( show("978-17343145020596528126")
show("978-17343145090596528120")
show("978-1788399081")
show("978-1788399083")
$)</syntaxhighlight>
{{out}}
<pre>978-17343145020596528126: good
978-17343145090596528120: bad
978-1788399081: good
978-1788399083: bad</pre>
Line 820:
int main() {
int i;
const char* isbns[] = {"978-17343145020596528126", "978-17343145090596528120", "978-1788399081", "978-1788399083"};
for (i = 0; i < 4; ++i) {
printf("%s: %s\n", isbns[i], check_isbn13(isbns[i]) ? "good" : "bad");
Line 829:
{{out}}
<pre>
978-17343145020596528126: good
978-17343145090596528120: bad
978-1788399081: good
978-1788399083: bad
Line 866:
 
int main() {
auto isbns = { "978-17343145020596528126", "978-17343145090596528120", "978-1788399081", "978-1788399083" };
for (auto isbn : isbns) {
std::cout << isbn << ": " << (check_isbn13(isbn) ? "good" : "bad") << '\n';
Line 874:
}</syntaxhighlight>
{{out}}
<pre>978-17343145020596528126: good
978-17343145090596528120: bad
978-1788399081: good
978-1788399083: bad</pre>
Line 886:
{
public static void Main() {
Console.WriteLine(CheckISBN13("978-17343145020596528126"));
Console.WriteLine(CheckISBN13("978-17343145090596528120"));
Console.WriteLine(CheckISBN13("978-1788399081"));
Console.WriteLine(CheckISBN13("978-1788399083"));
Line 931:
po: stream := stream$primary_output()
tests: array[string] := array[string]$
["978-17343145020596528126",
"978-17343145090596528120",
"978-1788399081",
"978-1788399083"]
Line 946:
end start_up</syntaxhighlight>
{{out}}
<pre>978-17343145020596528126: good
978-17343145090596528120: bad
978-1788399081: good
978-1788399083: bad</pre>
Line 980:
01 IX PIC S9(4) COMP.
01 TEST-ISBNS.
02 FILLER PIC X(14) VALUE '978-17343145020596528126'.
02 FILLER PIC X(14) VALUE '978-17343145090596528120'.
02 FILLER PIC X(14) VALUE '978-1788399081'.
02 FILLER PIC X(14) VALUE '978-1788399083'.
Line 1,096:
{{out}}
 
<pre>978-17343145020596528126 (good)
978-17343145090596528120 (bad)
978-1788399081 (good)
978-1788399083 (bad)
Line 1,129:
var isbns: [uint8][] := {
"978-17343145020596528126", "978-17343145090596528120", "978-1788399081", "978-1788399083"
};
Line 1,141:
end loop;</syntaxhighlight>
{{out}}
<pre>978-17343145020596528126: good
978-17343145090596528120: bad
978-1788399081: good
978-1788399083: bad</pre>
Line 1,168:
 
unittest {
assert(isValidISBN13("978-17343145020596528126"));
assert(!isValidISBN13("978-17343145090596528120"));
assert(isValidISBN13("978-1788399081"));
assert(!isValidISBN13("978-1788399083"));
Line 1,266:
 
proc nonrec main() void:
test("978-17343145020596528126");
test("978-17343145090596528120");
test("978-1788399081");
test("978-1788399083")
corp</syntaxhighlight>
{{out}}
<pre>978-17343145020596528126: good
978-17343145090596528120: bad
978-1788399081: good
978-1788399083: bad</pre>
Line 1,390:
|-
| style="text-align:center; font-family:Arial, Helvetica, sans-serif !important; background-color:#000000; color:#ffffff" | 2
| 978-17343145020596528126
| style="background-color:#cbcefb" | TRUE
|-
| style="text-align:center; font-family:Arial, Helvetica, sans-serif !important; background-color:#000000; color:#ffffff" | 3
| 978-17343145090596528120
| FALSE
|-
Line 1,419:
{ [ length 13 = ] [ [ digit? ] all? ] [ (isbn13?) ] } 1&& ;
 
qw{ 978-17343145020596528126 978-17343145090596528120 978-1788399081 978-1788399083 }
[ dup isbn13? "good" "bad" ? "%s: %s\n" printf ] each</syntaxhighlight>
{{out}}
<pre>
978-17343145020596528126: good
978-17343145090596528120: bad
978-1788399081: good
978-1788399083: bad
Line 1,442:
In Forth, a "true" value is indicated by "-1".
<pre>
s" 978-17343145020596528126" isbn? . -1 ok
s" 978-17343145090596528120" isbn? . 0 ok
s" 978-1788399081" isbn? . -1 ok
s" 978-1788399083" isbn? . 0 ok
Line 1,453:
implicit none
 
character(len=14), dimension(4), parameter :: isbns=["978-17343145020596528126", "978-17343145090596528120", "978-1788399081", "978-1788399083"]
integer :: i
 
Line 1,490:
{{out}}
<pre>
978-17343145020596528126 : good
978-17343145090596528120 : bad
978-1788399081 : good
978-1788399083 : bad
Line 1,525:
end function
 
dim as string isbns(0 to 3) = { "978-17343145020596528126", "978-17343145090596528120", "978-1788399081", "978-1788399083" }
dim as uinteger i
for i = 0 to 3
Line 1,537:
{{out}}
<pre>
978-17343145020596528126: good
978-17343145090596528120: bad
978-1788399081: good
978-1788399083: bad
Line 1,565:
 
{{out}}
<pre>978-17343145020596528126 Valid ISBN13
978-17343145090596528120 Inalid ISBN13
978-1788399081 Valid ISBN13
978-1788399083 Inalid ISBN13</pre>
Line 1,588:
<syntaxhighlight lang="vbnet">Public Sub Main()
Dim isbn As String[] = ["978-17343145020596528126", "978-17343145090596528120", "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
Line 1,645:
 
func main() {
isbns := []string{"978-17343145020596528126", "978-17343145090596528120", "978-1788399081", "978-1788399083"}
for _, isbn := range isbns {
res := "bad"
Line 1,657:
{{out}}
<pre>
978-17343145020596528126: good
978-17343145090596528120: bad
978-1788399081: good
978-1788399083: bad
Line 1,687:
mapM_
(printf "%s: Valid: %s\n" <*> (show . validIsbn13))
[ "978-17343145020596528126",
"978-17343145090596528120",
"978-1788399081",
"978-1788399083"
]</syntaxhighlight>
{{out}}
<pre>978-17343145020596528126: Valid: True
978-17343145090596528120: Valid: False
978-1788399081: Valid: True
978-1788399083: Valid: False</pre>
Line 1,715:
mapM_
(print . ((,) <*> isISBN13))
[ "978-17343145020596528126",
"978-17343145090596528120",
"978-1788399081",
"978-1788399083"
]</syntaxhighlight>
{{Out}}
<pre>("978-17343145020596528126",True)
("978-17343145090596528120",False)
("978-1788399081",True)
("978-1788399083",False)</pre>
Line 1,764:
{{out}}
 
<syntaxhighlight lang="j"> isbn13c;._1 ' 978-17343145020596528126 978-17343145090596528120 978-1788399081 978-1788399083'
1 0 1 0</syntaxhighlight>
 
Line 1,817:
An alternate demonstration
<syntaxhighlight lang="java">public static void main(){
System.out.println(isISBN13("978-17343145020596528126"));
System.out.println(isISBN13("978-17343145090596528120"));
System.out.println(isISBN13("978-1788399081"));
System.out.println(isISBN13("978-1788399083"));
Line 1,856:
 
def testingcodes:
["978-17343145020596528126", "978-17343145090596528120",
"978-1788399081", "978-1788399083"];
Line 1,864:
{{out}}
<pre>
978-17343145020596528126: good
978-17343145090596528120: bad
978-1788399081: good
978-1788399083: bad
Line 1,876:
end
 
const testingcodes = ["978-17343145020596528126", "978-17343145090596528120",
"978-1788399081", "978-1788399083"]
 
Line 1,884:
</syntaxhighlight>{{out}}
<pre>
978-17343145020596528126: good
978-17343145090596528120: bad
978-1788399081: good
978-1788399083: bad
Line 1,918:
describe("ISBN Utilities") {
mapOf(
"978-17343145020596528126" to true,
"978-17343145090596528120" to false,
"978-1788399081" to true,
"978-1788399083" to false
Line 1,935:
{{out}}
<pre>
978-17343145020596528126: good
978-17343145090596528120: bad
978-1788399081: good
978-1788399083: bad
Line 2,025:
 
function main()
test("978-17343145020596528126")
test("978-17343145090596528120")
test("978-1788399081")
test("978-1788399083")
Line 2,033:
main()</syntaxhighlight>
{{out}}
<pre>978-17343145020596528126: good
978-17343145090596528120: bad
978-1788399081: good
978-1788399083: bad</pre>
Line 2,051:
]
]
ValidISBNQ["978-17343145020596528126"]
ValidISBNQ["978-17343145090596528120"]
ValidISBNQ["978-1788399081"]
ValidISBNQ["978-1788399083"]</syntaxhighlight>
Line 2,128:
 
BEGIN
check('978-17343145020596528126');
check('978-17343145090596528120');
check('978-1788399081');
check('978-1788399083');
END ISBN.</syntaxhighlight>
{{out}}
<pre>978-17343145020596528126: good
978-17343145090596528120: bad
978-1788399081: good
978-1788399083: bad</pre>
Line 2,168:
end
 
isbns = {"978-17343145020596528126", "978-17343145090596528120", "978-1788399081", "978-1788399083"}
for isbn in isbns
res = "bad"
Line 2,178:
end</syntaxhighlight>
{{out}}
<pre>978-17343145020596528126: good
978-17343145090596528120: bad
978-1788399081: good
978-1788399083: bad</pre>
Line 2,197:
 
when is_main_module:
let isbns = [ "978-17343145020596528126", "978-17343145090596528120",
"978-1788399081", "978-1788399083" ]
for isbn in isbns:
Line 2,204:
{{out}}
<pre>
978-17343145020596528126: good
978-17343145090596528120: bad
978-1788399081: good
978-1788399083: bad
Line 2,292:
{ === MAIN ============================================================= }
begin
writeLn(isValidISBNString('978-17343145020596528126'));
writeLn(isValidISBNString('978-17343145090596528120'));
writeLn(isValidISBNString('978-1788399081'));
writeLn(isValidISBNString('978-1788399083'))
Line 2,314:
}
 
for (<978-17343145020596528126 978-17343145090596528120 978-1788399081 978-1788399083 978-2-74839-908-0 978-2-74839-908-5>) {
my($isbn,$check) = /(.*)(.)/;
my $check_d = check_digit($isbn);
Line 2,320:
}</syntaxhighlight>
{{out}}
<pre>978-17343145020596528126 : Good
978-17343145090596528120 : Bad check-digit 9; should be 2
978-1788399081 : Good
978-1788399083 : Bad check-digit 3; should be 1
Line 2,347:
<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-17343145020596528126"</span><span style="color: #0000FF;">,</span> <span style="color: #008000;">"978-17343145090596528120"</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: #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:
{{out}}
<pre>
978-17343145020596528126: good
978-17343145090596528120: bad
978-1788399081: good
978-1788399083: bad
Line 2,378:
(if (isbn13? A) 'ok 'fail) ) )
(quote
"978-17343145020596528126"
"978-17343145090596528120"
"978-1-86197-876-9"
"978-2-74839-908-5"
Line 2,385:
{{out}}
<pre>
978-17343145020596528126 ok
978-17343145090596528120 fail
978-1-86197-876-9 ok
978-2-74839-908-5 fail
Line 2,428:
/* TESTS */
DECLARE TEST (4) ADDRESS;
TEST(0) = .'978-17343145020596528126$';
TEST(1) = .'978-17343145090596528120$';
TEST(2) = .'978-1788399081$';
TEST(3) = .'978-1788399083$';
Line 2,447:
EOF</syntaxhighlight>
{{out}}
<pre>978-17343145020596528126: GOOD
978-17343145090596528120: BAD
978-1788399081: GOOD
978-1788399083: BAD</pre>
Line 2,456:
function Get-ISBN13 {
$codes = (
"978-17343145020596528126",
"978-17343145090596528120",
"978-1788399081",
"978-1788399083"
Line 2,496:
{{out}}
<pre>
978-17343145020596528126 Good
978-17343145090596528120 Bad
978-1788399081 Good
978-1788399083 Bad
Line 2,518:
 
If OpenConsole()
TestISBN13("978-17343145020596528126")
TestISBN13("978-17343145090596528120")
TestISBN13("978-1788399081")
TestISBN13("978-1788399083")
Line 2,525:
EndIf</syntaxhighlight>
{{out}}
<pre>978-17343145020596528126 good
978-17343145090596528120 bad
978-1788399081 good
978-1788399083 bad
Line 2,542:
if __name__ == '__main__':
tests = '''
978-17343145020596528126
978-17343145090596528120
978-1788399081
978-1788399083'''.strip().split()
Line 2,550:
 
{{out}}
<pre>ISBN13 978-17343145020596528126 validates True
ISBN13 978-17343145090596528120 validates False
ISBN13 978-1788399081 validates True
ISBN13 978-1788399083 validates False</pre>
Line 2,587:
print('\n'.join(
repr((s, isISBN13(s))) for s
in ["978-17343145020596528126",
"978-17343145090596528120",
"978-1788399081",
"978-1788399083"
Line 2,600:
</syntaxhighlight>
{{Out}}
<pre>('978-17343145020596528126', True)
('978-17343145090596528120', False)
('978-1788399081', True)
('978-1788399083', False)</pre>
Line 2,634:
else [ say "Bad" ] cr ] is isbn-test ( $ --> )
 
$ '978-17343145020596528126' isbn-test
$ '978-17343145090596528120' isbn-test
$ '978-1788399081' isbn-test
$ '978-1788399083' isbn-test</syntaxhighlight>
{{out}}
<pre>
978-17343145020596528126: Good
978-17343145090596528120: Bad
978-1788399081: Good
978-1788399083: Bad
Line 2,659:
(module+ test
(require rackunit)
(check-true (isbn13-check-digit-valid? "978-17343145020596528126"))
(check-false (isbn13-check-digit-valid? "978-17343145090596528120"))
(check-true (isbn13-check-digit-valid? "978-1788399081"))
(check-false (isbn13-check-digit-valid? "978-1788399083")))</syntaxhighlight>
Line 2,683:
"Bad check-digit $check; should be $check-digit"
} for words <
978-17343145020596528126
978-17343145090596528120
978-1788399081
978-1788399083
Line 2,691:
>;</syntaxhighlight>
{{out}}
<pre>978-17343145020596528126 : Good
978-17343145090596528120 : Bad check-digit 9; should be 2
978-1788399081 : Good
978-1788399083 : Bad check-digit 3; should be 1
Line 2,719:
 
; check given examples
foreach [str] ["978-17343145020596528126" "978-17343145090596528120" "978-1788399081" "978-1788399083"] [
prin str
prin " - "
Line 2,728:
{{out}}
<pre>
978-17343145020596528126 - true
978-17343145090596528120 - false
978-1788399081 - true
978-1788399083 - false
Line 2,738:
<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*/
if $='' | if $="," then $= '978-17343145020596528126 978-17343145090596528120 978-1788399081 978-1788399083'
@ISBN= "ISBN─13 code isn't" /*a literal used when displaying msgs. */
/* [↓] remove all minuses from X code.*/
Line 2,767:
load "stdlib.ring"
 
isbn = ["978-17343145020596528126","978-17343145090596528120", "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)
Line 2,792:
Output:
<pre>
978-17343145020596528126: true
978-17343145090596528120: bad
978-1788399081: true
978-1788399083: bad
Line 2,834:
end
 
isbns = ["978-17343145020596528126", "978-17343145090596528120", "978-1788399081", "978-1788399083"]
isbns.each{|isbn| puts "#{isbn}: #{validISBN13?(isbn)}" }
</syntaxhighlight>{{out}}
<pre>978-17343145020596528126: true
978-17343145090596528120: false
978-1788399081: true
978-1788399083: false
Line 2,845:
=={{header|Rust}}==
<syntaxhighlight lang="rust">fn main() {
let isbns = ["978-17343145020596528126", "978-17343145090596528120", "978-1788399081", "978-1788399083"];
isbns.iter().for_each(|isbn| println!("{}: {}", isbn, check_isbn(isbn)));
}
Line 2,861:
{{out}}
<pre>
978-17343145020596528126: true
978-17343145090596528120: false
978-1788399081: true
978-1788399083: false
Line 2,898:
var string: str is "";
begin
for str range [] ("978-17343145020596528126", "978-17343145090596528120", "978-1788399081", "978-1788399083") do
writeln(str <& ": " <& isISBN13(str));
end for;
Line 2,904:
{{out}}
<pre>
978-17343145020596528126: TRUE
978-17343145090596528120: FALSE
978-1788399081: TRUE
978-1788399083: FALSE
Line 2,922:
end
 
val test = ["978-17343145020596528126", "978-17343145090596528120", "978-1788399081", "978-1788399083"]
val () = (print
o concat
o map (fn s => s ^ (if checkISBN s then ": good\n" else ": bad\n"))) test</syntaxhighlight>
{{out}}
<pre>978-17343145020596528126: good
978-17343145090596528120: bad
978-1788399081: good
978-1788399083: bad</pre>
Line 2,949:
 
let cases = [
"978-17343145020596528126",
"978-17343145090596528120",
"978-1788399081",
"978-1788399083"
Line 2,962:
{{out}}
 
<pre>978-17343145020596528126 => good
978-17343145090596528120 => bad
978-1788399081 => good
978-1788399083 => bad</pre>
Line 2,984:
}
foreach test {
978-17343145020596528126
978-17343145090596528120
978-1788399081
978-1788399083
Line 2,991:
</syntaxhighlight>
{{out}}
<pre>978-17343145020596528126:true
978-17343145090596528120:false
978-1788399081:true
978-1788399083:false</pre>
Line 3,013:
=={{header|uBasic/4tH}}==
{{works with|version 3.64.0}}
<syntaxhighlight lang="text">a := "978-17343145020596528126"
Print Show(a), Show (Iif (Func(_IsISBN (a)), "good", "bad"))
 
a := "978-17343145090596528120"
Print Show(a), Show (Iif (Func(_IsISBN (a)), "good", "bad"))
 
Line 3,041:
Return ((c@ % 10) = 0) ' modulus 10 must be zero</syntaxhighlight>
{{out}}
<pre>978-17343145020596528126 good
978-17343145090596528120 bad
978-1788399081 good
978-1788399083 bad
Line 3,060:
}
 
for isbn in 978-17343145020596528126 978-17343145090596528120 978-1788399081 978-1788399083; do
printf '%s: ' "$isbn"
if check_isbn13 "$isbn"; then
Line 3,069:
done</syntaxhighlight>
{{Out}}
<pre>978-17343145020596528126: OK
978-17343145090596528120: NOT OK
978-1788399081: OK
978-1788399083: NOT OK</pre>
Line 3,097:
 
Sub Main()
Console.WriteLine(CheckISBN13("978-17343145020596528126"))
Console.WriteLine(CheckISBN13("978-17343145090596528120"))
Console.WriteLine(CheckISBN13("978-1788399081"))
Console.WriteLine(CheckISBN13("978-1788399083"))
Line 3,137:
fn main() {
isbns := ["978-17343145020596528126", "978-17343145090596528120", "978-1788399081", "978-1788399083"]
for isbn in isbns {
mut res := "bad"
Line 3,149:
{{out}}
<pre>
978-17343145020596528126: good
978-17343145090596528120: bad
978-1788399081: good
978-1788399083: bad
Line 3,173:
}
 
var tests = ["978-17343145020596528126", "978-17343145090596528120", "978-1788399081", "978-1788399083"]
for (test in tests) {
System.print("%(test) -> %(isbn13.call(test) ? "good" : "bad")")
Line 3,180:
{{out}}
<pre>
978-17343145020596528126 -> good
978-17343145090596528120 -> bad
978-1788399081 -> good
978-1788399083 -> bad
Line 3,207:
];
 
[ISBN13("978-17343145020596528126");
ISBN13("978-17343145090596528120");
ISBN13("978-1788399081");
ISBN13("978-1788399083");
Line 3,217:
{{out}}
<pre>
978-17343145020596528126: good
978-17343145090596528120: bad
978-1788399081: good
978-1788399083: bad
Line 3,226:
 
=={{header|zkl}}==
<syntaxhighlight lang="zkl">fcn ISBN13_check(isbn){ // "978-17343145020596528126", throws on invalid 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
Line 3,233:
<syntaxhighlight lang="zkl">isbns:=
#<<<"
978-17343145020596528126
978-17343145090596528120
978-1788399081
978-1788399083
Line 3,244:
{{out}}
<pre>
978-17343145020596528126 Good
978-17343145090596528120 Bad
978-1788399081 Good
978-1788399083 Bad
885

edits