Skip to content

Instantly share code, notes, and snippets.

@gkucmierz
Created January 31, 2022 17:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gkucmierz/283a9a2119803cecc54931f1b2c9b97d to your computer and use it in GitHub Desktop.
Save gkucmierz/283a9a2119803cecc54931f1b2c9b97d to your computer and use it in GitHub Desktop.
// http://www.pleacher.com/handley/puzzles/blackhol.html
const randBI = () => {
const maxLen = 10_000;
return BigInt(new Array(Math.round(Math.random() * maxLen))
.fill(0)
.map(_ => Math.round(Math.random() * 10) % 10)
.join(''))
};
const test123 = () => {
let bi = randBI();
let last;
while (bi !== last) {
const arr = [...bi + ''];
const even = arr.reduce((cnt, n) => {
return cnt + (+n % 2 === 0 ? 1 : 0);
}, 0);
const odd = arr.length - even;
last = bi
bi = BigInt([even, odd, arr.length].join(''));
}
return bi;
}
const map = new Map();
for (let i = 0; i < 1e6; ++i) {
const bi = test123();
const cnt = map.get(bi) || 0;
map.set(bi, cnt + 1);
if (i % 1e3 === 0) {
console.log(i, map);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment