Tuesday, January 08, 2008

10桁ISBNのチェックディジットの計算

def add_checksum(isbn)
  v = 0
  (0..8).each { |i|
    v += isbn[i,1].to_i * (i+1)
  }
  v %= 11
  checksum = (v == 10 ? 'X' : v.to_s)
  isbn + checksum
end

0 Comments:

Post a Comment

Links to this post:

Create a Link

<< Home