Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
37
Task/ISBN13-check-digit/Delphi/isbn13-check-digit.delphi
Normal file
37
Task/ISBN13-check-digit/Delphi/isbn13-check-digit.delphi
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
function ValidateISBN(ISBN: string): boolean;
|
||||
{Validate an ISBN number}
|
||||
var I,N,Sum: integer;
|
||||
begin
|
||||
Sum:=0;
|
||||
{Go througha chars, ignoring non-digits}
|
||||
for I:=1 to Length(ISBN) do
|
||||
if ISBN[I] in ['0'..'9'] then
|
||||
begin
|
||||
N:=StrToInt(ISBN[I]);
|
||||
{Every other digit multiplied by 3}
|
||||
if (I and 1)=1 then N:=N*3;
|
||||
{Sum digits}
|
||||
Sum:=Sum+N;
|
||||
end;
|
||||
{The sum must be an even multiple of 10}
|
||||
Result:=(Sum mod 10)=0;
|
||||
end;
|
||||
|
||||
procedure ValidateAndShow(Memo: TMemo; ISBN: string);
|
||||
{Validate ISBN number and show the result}
|
||||
var S: string;
|
||||
begin
|
||||
S:=ISBN;
|
||||
if ValidateISBN(ISBN) then S:=S+' (Good)'
|
||||
else S:=S+' (Bad)';
|
||||
Memo.Lines.Add(S);
|
||||
end;
|
||||
|
||||
procedure TestISBNSet(Memo: TMemo);
|
||||
{Test supplied set of ISBN numbers}
|
||||
begin
|
||||
ValidateAndShow(Memo,'978-0596528126'); //(good)
|
||||
ValidateAndShow(Memo,'978-0596528120'); //(bad)
|
||||
ValidateAndShow(Memo,'978-1788399081'); //(good)
|
||||
ValidateAndShow(Memo,'978-1788399083'); //(bad)
|
||||
end;
|
||||
Loading…
Add table
Add a link
Reference in a new issue