Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
23
Task/ISBN13-check-digit/Red/isbn13-check-digit.red
Normal file
23
Task/ISBN13-check-digit/Red/isbn13-check-digit.red
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
check_valid_isbn13: function [str] [
|
||||
is_digit: charset [#"0" - #"9"]
|
||||
remove-each i str [not pick is_digit i] ; remove non-digits
|
||||
|
||||
either 13 = length? str [ ; reject strings of incorrect length
|
||||
sum: 0
|
||||
repeat i 13 [
|
||||
mul: either even? i [3] [1] ; multiplier for odd/even digits
|
||||
sum: sum + (mul * to integer! to string! pick str i)
|
||||
]
|
||||
|
||||
zero? (sum % 10) ; check if remainder mod 10 is zero
|
||||
] [
|
||||
false
|
||||
]
|
||||
]
|
||||
|
||||
; check given examples
|
||||
foreach [str] ["978-1734314502" "978-1734314509" "978-1788399081" "978-1788399083"] [
|
||||
prin str
|
||||
prin " - "
|
||||
print check_valid_isbn13 str
|
||||
]
|
||||
Loading…
Add table
Add a link
Reference in a new issue