RosettaCodeData/Task/ISBN13-check-digit/FutureBasic/isbn13-check-digit.basic
2024-11-04 21:53:44 -08:00

21 lines
514 B
Text

BOOL local fn IsGoodISBN( isbn as CFStringRef )
int sum = 0
for int i = 0 to len(isbn) - 1
unichar chr = ucc(isbn,i) - 48
if ( chr > 0 && chr <= 9 )
if ( i % 2 == 0 ) then sum += chr * 3 else sum += chr
end if
next
end fn = sum % 10 == 0
void local fn DoIt
CFArrayRef a = @[@"978-0596528126",@"978-0596528120",@"978-1788399081",@"978-1788399083"]
for CFStringRef s in a
print s,
if ( fn IsGoodISBN(s) ) then print @"good" else print @"bad"
next
end fn
fn DoIt
HandleEvents