Skip to content

Instantly share code, notes, and snippets.

@KarlHerler
Created August 24, 2011 07:17
Show Gist options
  • Save KarlHerler/1167467 to your computer and use it in GitHub Desktop.
Save KarlHerler/1167467 to your computer and use it in GitHub Desktop.
Calculating finnish banking reference numbers (Viitenumerot) in ruby
def refnr(source)
#this takes a ID string with number but declared as string and returns a valid reference number
chk = 0 #the integrity check number
weights = [7, 3, 1] #hash weights, declared by THE GOVERNMENT
source.split('').reverse.each_with_index { |x, i| chk += (x.to_i)*weights[i%3] } #does the caluclation
return "#{source}#{((10-(chk%10))%10)}" #returns the input number with the check number trailing it
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment