ISBN13 check digit: Difference between revisions

(Added Fōrmulæ solution)
Line 1,413:
</pre>
 
=={{header|jq}}==
{{works with|jq}}
'''Works with gojq, the Go implementation of jq'''
<lang jq>
def isbn_check:
def digits: tostring | explode | map( select(. >= 48 and . <= 57) | [.] | implode | tonumber);
def sum(s): reduce s as $x (null; . + $x);
digits
| . as $digits
| sum(range(0;length;2) | $digits[.]) as $one
| (3 * sum(range(1;length;2) | $digits[.])) as $two
| (($one+$two) % 10) == 0;
 
def testingcodes:
["978-1734314502", "978-1734314509",
"978-1788399081", "978-1788399083"];
testingcodes[]
| "\(.): \(if isbn_check then "good" else "bad" end)"
</lang>
{{out}}
<pre>
978-1734314502: good
978-1734314509: bad
978-1788399081: good
978-1788399083: bad
</pre>
=={{header|Julia}}==
<lang julia>function isbncheck(str)
2,496

edits