Skip to content

Instantly share code, notes, and snippets.

@squiter
Created April 22, 2015 01:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save squiter/cf4e474b8b51251c5085 to your computer and use it in GitHub Desktop.
Save squiter/cf4e474b8b51251c5085 to your computer and use it in GitHub Desktop.
Mod 11 - Módulo 11
def mod11(number, total)
as_string = number.to_s
sub = as_string.length
value = 0
max = total
sub.times do |t|
value += as_string[t].to_i * max
max = max - 1
end
mod = (value % 11)
mod = 0 if mod == 0 || mod == 1
digito = total - mod
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment