Created
January 31, 2022 17:00
-
-
Save gkucmierz/283a9a2119803cecc54931f1b2c9b97d to your computer and use it in GitHub Desktop.
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
// 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