Hi,

after reading the link and some additional sources, it turns out that a
valid ISBN-10 has either no separators or four blocks separated by either
dashes or spaces:
  Group-Publisher-Title-CheckDigit

Assuming Regex11 (and that I made no mistake), the following should do the
trick:

IsbnVarifier>>isSyntacticIsbn: aString
  "no groups"
  noGrouped := '\d{9}[0-9X]' asRegex.
  "groups separated by either dashes or spaces"
  dashes := '\d{1,7}-\d{1,7}-\d{1,7}-[0-9X]'
  spaces := '\d{1,7} \d{1,7} \d{1,7} [0-9X]'
  grouped := (dashed , '|' , spaces) asRegex.

  ^(aString matches: nonGrouped) or:
    [(aString matches: grouped) and:
      [aString size = 10 + 3]]

Surely, you could cleverly compress the regex even further but that does
not matter for this example. After checking the syntax, you can just
iterate over the string and compute the check-digit on the fly.

Kind regards,
Steffen

Am .09.2020, 18:19 Uhr, schrieb Roelof Wobben via Pharo-users
<pharo-users@lists.pharo.org>:

See here for all the tests :
https://github.com/exercism/pharo-smalltalk/blob/master/exercises/isbn-verifier/IsbnVerifierTest.class.st#L88

Roelof




Reply via email to