How to resolve the algorithm ISBN13 check digit step by step in the Seed7 programming language

Published on 12 May 2024 09:40 PM

How to resolve the algorithm ISBN13 check digit step by step in the Seed7 programming language

Table of Contents

Problem Statement

Validate the check digit of an ISBN-13 code:

You might use the following codes for testing:

Show output here, on this page

Let's start with the solution:

Step by Step solution about How to resolve the algorithm ISBN13 check digit step by step in the Seed7 programming language

Source code in the seed7 programming language

$ include "seed7_05.s7i";

const func boolean: isISBN13 (in var string: input) is func
  result
    var boolean: isbn is FALSE;
  local
    var char: c is ' ';
    var integer: digit is 0;
    var integer: i is 1;
    var integer: sum is 0;
  begin
    input := replace(input, " ", "");
    input := replace(input, "-", "");
    if length(input) = 13 then
      for c range input do
        digit := ord(c) - 48;
        if not odd(i) then
          digit *:= 3;
        end if;
        sum +:= digit;
        incr(i);
      end for;
      isbn := sum rem 10 = 0;
    end if;
  end func;

const proc: main is func
  local
    var string: str is "";
  begin
    for str range [] ("978-1734314502", "978-1734314509", "978-1788399081", "978-1788399083") do
      writeln(str <& ": " <& isISBN13(str));
    end for;
  end func;

  

You may also check:How to resolve the algorithm Sort numbers lexicographically step by step in the Isabelle programming language
You may also check:How to resolve the algorithm Stack traces step by step in the PicoLisp programming language
You may also check:How to resolve the algorithm Averages/Mean angle step by step in the ALGOL 68 programming language
You may also check:How to resolve the algorithm Operator precedence step by step in the PHP programming language
You may also check:How to resolve the algorithm Matrix multiplication step by step in the ZPL programming language