Came to a same thesis and worked out a similar solution. Also ran into the limits at the 9th perfect number. But JavaScript now supports native BigInt (only in Chrome and I believe newer versions of NodeJs though!). Now we just need a way to generate large prime numbers fast to generate perfect numbers. 😉
First dumb "look at every integer" solution:
This algo has trouble going further than 1e6.
Then, I dig your hypothesis that all Perfect number are in the form
(n+1)"1"..(n)"0"
in base 2. I needed to find the logical sequence of valid n.So I looked up this sequence on EOIS and luckily it found a match: "Numbers n such that 2n+1 - 1 is prime".
Which lead to this way more powerful script:
This time, it can't go any higher than 1e3 before crashing, but yield more results. (However, JS precision let me down on the last result)
Came to a same thesis and worked out a similar solution. Also ran into the limits at the 9th perfect number. But JavaScript now supports native BigInt (only in Chrome and I believe newer versions of NodeJs though!). Now we just need a way to generate large prime numbers fast to generate perfect numbers. 😉
Yeah, I liked that we came with two solution from the same hypothesis.
I'm looking into BigInt (thanks a lot I didn't know !) and it looks promising.
Thanks to your input on BigInt, I made a new solution.
Thanks a lot !
👏👏👏👏👏👏
I feel a heart is not enough. I'm so happy to see the new version.