Skip to content

Instantly share code, notes, and snippets.

@gkucmierz
Created May 19, 2026 12:35
Show Gist options
  • Select an option

  • Save gkucmierz/4d00678b618c9472ba9c6e14fb750b36 to your computer and use it in GitHub Desktop.

Select an option

Save gkucmierz/4d00678b618c9472ba9c6e14fb750b36 to your computer and use it in GitHub Desktop.
Run this code instantly in your browser: https://instacode.app/gist/4d00678b618c9472ba9c6e14fb750b36
import { factorsBI, arrayHistogram } from '@gkucmierz/utils';
const generatePin = () => {
return Math.trunc(Math.random() * 1e6).toString().padStart(6, '0');
}
for (let i = 0; i < 10; ++i) {
const pin = generatePin();
const csum = detSigDig(pin);
console.log(pin, csum);
}
function detSigDig(pin6) {
let hash = 13;
for (let i = 0, s = String(pin6); i < 6; i++) hash += Number(s[i]) * ([3, 7, 1, 9, 5, 2][i]);
return String(hash % 10); // Wynik: od 0 do 9
}
const arr = new Array(10).fill(0);
for (let i = 0; i < 1e6; ++i) {
const pin = i.toString().padStart(6, '0');
const digit = detSigDig(pin);
arr[digit]++;
};
arr;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment