Skip to content

Instantly share code, notes, and snippets.

@0xd61
Forked from mewelling/ruc_calc.js
Created November 11, 2019 19:42
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save 0xd61/058f76dbf481839d2c938c8c7e17dd5c to your computer and use it in GitHub Desktop.
Save 0xd61/058f76dbf481839d2c938c8c7e17dd5c to your computer and use it in GitHub Desktop.
Paraguay Cédula + RUC calculation
/*
To calculate the RUC number for your cedula:
Starting with the rightmost digit, multiply it by 2.
Then, multiply the next digit by 3 and add it to the first result.
Then, multiply the next digit by 4 and add it to the running total.
... keep doing this.
Finally, take the remainder of the the total divided by 11 (called the modulo),
and subtract it from 11.
original inspiration: http://www.necesitomas.com/digito-verificador
*/
// TEST
const cedula = '8765432'; // RUC: 8765432-6
const digits = cedula.split("").reverse().map(x => parseInt(x));
let total = 0;
digits.forEach((digit, index) => {
total += digit * (index + 2);
});
console.log('RUC:', `${cedula}-${11 - total % 11}`);
@0xd61
Copy link
Author

0xd61 commented Nov 11, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment