-
-
Save DiegoArrieta/3153b91c436e2b11adcb6c3c697d9478 to your computer and use it in GitHub Desktop.
Dígito verificador del RUT en Python
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# encoding=utf-8 | |
# Obtener el dígito verificador del RUT en Python. | |
# | |
# La función recibe el RUT como un entero, | |
# y entrega el dígito verificador como un entero. | |
# Si el resultado es 10, el RUT es "raya k". | |
from itertools import cycle | |
def digito_verificador(rut): | |
reversed_digits = map(int, reversed(str(rut))) | |
factors = cycle(range(2, 8)) | |
s = sum(d * f for d, f in zip(reversed_digits, factors)) | |
return (-s) % 11 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment