Skip to content

Instantly share code, notes, and snippets.

@singpolyma
Created June 1, 2011 18:43
Show Gist options
  • Save singpolyma/1002978 to your computer and use it in GitHub Desktop.
Save singpolyma/1002978 to your computer and use it in GitHub Desktop.
Convert ISBN10 to ISBN13
def isbn10_to_isbn13(isbn10)
i = 30
s = '978' + isbn10.to_s[0..8]
4.step(12, 2) do |j|
i += s[j-2, 1].to_i + (3 * s[j-1, 1].to_i)
end
s + ((10 - (i % 10)) % 10).to_s
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment