-
-
Save habere-et-dispertire/d640a8f3e487df4012dfb635780e4afa to your computer and use it in GitHub Desktop.
[Raku] ISBN Verifier
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
grammar ISBN { | |
token TOP { <tenner> | <niner-xray> } | |
token tenner { [ <digit> <:Pd> ? ] ** 10 } | |
token niner-xray { [ <digit> <:Pd> ? ] ** 9 X } | |
} | |
class ISBN::Verify { | |
method TOP ( $/ ) { | |
make sum( $_ Z× ( 10...1 ) ) %% 11 with flat | |
$<tenner><digit> // $<niner-xray><digit>, 10 | |
} | |
} | |
sub is-isbn10 ( $barcode ) is export { | |
ISBN.parse( $barcode, actions => ISBN::Verify ) | |
.made | |
// False | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment