ISBN13 check digit: Difference between revisions

Added uBasic/4tH version
(Optimized routine beyond the specs of my original one)
(Added uBasic/4tH version)
Line 2,345:
</lang>
 
=={{header|uBasic/4tH}}==
{{works with|version 3.64.0}}
<lang>a := "978-1734314502"
Print Show(a), Show (Iif (Func(_IsISBN (a)), "good", "bad"))
 
a := "978-1734314509"
Print Show(a), Show (Iif (Func(_IsISBN (a)), "good", "bad"))
 
a := "978-1788399081"
Print Show(a), Show (Iif (Func(_IsISBN (a)), "good", "bad"))
 
a := "978-1788399083"
Print Show(a), Show (Iif (Func(_IsISBN (a)), "good", "bad"))
 
End
 
_IsISBN
Param (1)
Local (4)
 
c@ = 0 : e@ = 1 ' set sum and multiplier
 
For b@ = Len (a@) - 1 To 0 Step -1 ' scan string in reverse
d@ = Peek(a@, b@) - Ord ("0") ' get character
If ((d@ < 0) + (d@ > 9)) = 0 Then c@ = c@ + (d@ * e@)
e@ = (e@ * 3) % 8 ' evaluate character, change multiplier
Next
 
Return ((c@ % 10) = 0) ' modulus 10 must be zero</lang>
{{out}}
<pre>978-1734314502 good
978-1734314509 bad
978-1788399081 good
978-1788399083 bad
 
0 OK, 0:339</pre>
=={{header|UNIX Shell}}==
{{works with|Bourne Again Shell}}
374

edits