Skip to content

Instantly share code, notes, and snippets.

@pahnin
Last active December 17, 2015 12:09
Show Gist options
  • Save pahnin/5607608 to your computer and use it in GitHub Desktop.
Save pahnin/5607608 to your computer and use it in GitHub Desktop.
ISBN13 barcode
#! /bin/env ruby
def isbn(inp)
switch=true
sum=0
inp.to_s.split('').each do |i|
if switch
sum=sum+i.to_i
switch=false
else
sum=sum+(i.to_i)*3
switch=true
end
end
puts sum%10 > 0 ? (inp*10)+10-(sum%10) : inp*10
end
isbn(978014300723)
isbn(978014300763)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment