Skip to content

Instantly share code, notes, and snippets.

@sharmaabhinav
Last active December 25, 2015 16:29
Show Gist options
  • Save sharmaabhinav/7006263 to your computer and use it in GitHub Desktop.
Save sharmaabhinav/7006263 to your computer and use it in GitHub Desktop.
no = ARGV[0].to_i
copy_no = no
check_digit = 0
for i in 2..13
if i%2 !=0
check_digit = check_digit + (copy_no%10) * 1
else
check_digit = check_digit + (copy_no%10) * 3
end
copy_no = copy_no/10
end
check_digit = 10 - check_digit%10
check_digit = 0 if check_digit == 10
no = no*10 + check_digit
puts no
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment