All pastes #754059 Raw Edit

Anonymous

public ruby v1 · immutable
#754059 ·published 2007-10-29 19:16 UTC
rendered paste body
require 'pp'class Validate_ptbr        def Validate_ptbr.cpf()                cpf_invalid_array = ["00000000000",                             "11111111111",                             "22222222222",                             "33333333333",                             "44444444444",                             "55555555555",                             "66666666666",                             "77777777777",                             "88888888888",                             "99999999999"]                case        when cpf.length != 11 OR !cpf_invalid_array.include?(cpf)            return false        end                cpf_hash = Hash.new            for i in 0..10            cpf_hash[i] = cpf[i,1].to_i        end                sum = 0        j = 0                for i in 10..2            sum += i * cpf_hash[j++]        end          	sum -= 11 * (sum / 11)                result1 = sum == 0 || $sum == 1 ? 0 : 11 - $sum                if result1 != cpf_has[9] 	    return false        else            j = 11; sum = 0                        for i in 0..9                sum += cpf_hash[i] * j--            end                               sum -= 11 * (sum / 11) 	                     	    result2 = sum == 0 || sum == 1 ? 0 : 11 - sum 	                   	    return result2 == cpf_hash[10]        end    endend