ISBN13 check digit: Difference between revisions
Content added Content deleted
(add PicoLisp) |
(Add Factor) |
||
Line 84: | Line 84: | ||
}</lang> |
}</lang> |
||
{{out}} |
|||
<pre> |
|||
978-1734314502: good |
|||
978-1734314509: bad |
|||
978-1788399081: good |
|||
978-1788399083: bad |
|||
</pre> |
|||
=={{header|Factor}}== |
|||
<lang factor>USING: combinators.short-circuit formatting kernel math |
|||
math.parser math.vectors qw sequences sequences.extras sets |
|||
unicode ; |
|||
: (isbn13?) ( str -- ? ) |
|||
string>digits |
|||
[ <evens> sum ] [ <odds> 3 v*n sum + ] bi 10 mod zero? ; |
|||
: isbn13? ( str -- ? ) |
|||
"- " without |
|||
{ [ length 13 = ] [ [ digit? ] all? ] [ (isbn13?) ] } 1&& ; |
|||
qw{ 978-1734314502 978-1734314509 978-1788399081 978-1788399083 } |
|||
[ dup isbn13? "good" "bad" ? "%s: %s\n" printf ] each</lang> |
|||
{{out}} |
{{out}} |
||
<pre> |
<pre> |