记录一下。
#encoding:utf-8
def get_check_char(input)
checksum = 0
input.slice(0,18).chars.reverse.each_with_index do |e,i|
t = e.to_i
if i % 2 == 0
t *= 2
t -= 9 if t > 9
end
checksum += t
end
((checksum % 10) == 0 ? 0.to_s : (10 - (checksum % 10)).to_s)
end
def check_valid?(input)
input.slice(18,1) == get_check_char(input)
end
1.times do |x|
puts check_valid?('6222600000001111101')
puts get_check_char('6222600000001111101')
end
1065

被折叠的 条评论
为什么被折叠?



