Created
November 29, 2015 15:23
-
-
Save nocd5/cfdfa2649a681998f5e5 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def get_check_digit (number) | |
sum = 0 | |
number[0,11].reverse.split(//).each_with_index {|n, i| | |
sum += n.to_i * (i % 6 + 2) | |
} | |
return sum <= 1 ? 0 : 11 - sum % 11 | |
end | |
puts "Please input your number" | |
number = gets.chomp | |
if number.length != 12 then | |
puts "Invalid number" | |
exit | |
else | |
if get_check_digit(number) == number[11].to_i then | |
puts "Check Digit is valid" | |
else | |
puts "Check Digit is NOT valid" | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment