Skip to content

Instantly share code, notes, and snippets.

@lokimeyburg
Created October 26, 2012 23:43
Show Gist options
  • Save lokimeyburg/3962251 to your computer and use it in GitHub Desktop.
Save lokimeyburg/3962251 to your computer and use it in GitHub Desktop.
Generate your own valid Canadian Medical Services Plan number.
def valid_msp_number(msp_number)
weights = [0, 2, 4, 8, 5, 10, 9, 7, 3, 0]
total = 0
weights.to_enum.with_index(1).each do |weight, i|
total = total + msp_number[i-1].to_i * weight.to_i
end
a = total / 11
b = a * 11
c = total - b
result = 11 - c
if msp_number[-1].to_i != result
puts "not valid"
end
end
15.times do
weights = [2, 4, 8, 5, 10, 9, 7, 3]
int0 = 9;
random_numbers = Array.new
total = 0
weights.each do |i|
random_numbers << rand(9)
calculated = i * random_numbers.last
total += calculated
end
a = total / 11
b = a * 11
c = total - b
result = 11 - c
num = '9' + random_numbers.join + result.to_s
if num.length == 10
puts num
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment