Skip to content

Instantly share code, notes, and snippets.

@robhoare
Last active March 27, 2022 04:54
Show Gist options
  • Save robhoare/6f6b3fa96795340dc4fd8214aebd861e to your computer and use it in GitHub Desktop.
Save robhoare/6f6b3fa96795340dc4fd8214aebd861e to your computer and use it in GitHub Desktop.
Calcular el noveno dígito de un DNI peruano
Calculate the ninth digit of a Peruvian DNI (English description after Spanish)
Espanol:
Calcular el noveno dígito de un DNI peruano
===========================================
Multiplica cada dígito del DNI por el dígito correspondiente en:
3 2 7 6 5 4 3 2
Ejemplo DNI: 4 2 3 8 8 6 0 4
así, el primer dígito del DNI se multiplica por 3, el segundo por 2,
el tercero por 7, y así sucesivamente.
3 2 7 6 5 4 3 2
x x x x x x x x
4 2 3 8 8 6 0 4
= = = = = = = =
12 7 21 48 40 24 0 8
Súmalos (12+7+21...).
ejemplo total es 157.
Encuentra el módulo 11 de este número (el número desde el último múltiplo de 11).
11x14 es 154, entonces el módulo es 157-154 = 3.
Resta esto de 11. 11-3 = 8.
(si el resultado es 11, cámbielo a cero).
Ahora busque ese número en la primera fila en la tabla a continuación. El noveno
número está en la fila de abajo.
0 1 2 3 4 5 6 7 8 9 10
6 7 8 9 0 1 1 2 3 4 5
Entonces, si buscas 8, el dígito final está en la fila de abajo: 3.
3 es el número de su noveno dígito, en este ejemplo.
Algunos DNI tienen una letra al final, en lugar de un número (no sé por qué).
En este caso, búscalas en esta tabla:
0 1 2 3 4 5 6 7 8 9 10
K A B C D E F G H I J
(así que si busca 8, la letra final es H).
English:
Calculate the ninth digit of a Peruvian DNI
===========================================
Multiply each digit in the DNI by the corresponding digit in:
3 2 7 6 5 4 3 2
Example DNI: 4 2 3 8 8 6 0 4
so, the first digit in DNI is multiplied by 3, the second by 2,
the third by 7, and so on.
3 2 7 6 5 4 3 2
x x x x x x x x
4 2 3 8 8 6 0 4
= = = = = = = =
12 7 21 48 40 24 0 8
Add these up (12+7+21...).
example total is 157.
Find the modulo 11 of this number (the number since the last multiple of 11).
11x14 is 154, so the modulo is 157-154 = 3.
Subtract this from 11. 11-3 = 8.
(if the result is 11, change it to zero).
Now look up that number in the first row in table below. The ninth
number is in the row below.
0 1 2 3 4 5 6 7 8 9 10
6 7 8 9 0 1 1 2 3 4 5
So, if you look up 8, the final digit is in the row below: 3.
3 is the number of your ninth digit, in this example.
Some DNI have a letter at the end, instead of a number (I don't know why).
In this case, look them up in this table:
0 1 2 3 4 5 6 7 8 9 10
K A B C D E F G H I J
(so if you look up 8, the final letter is H).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment